<template>
  <pageTabelLayout>
    <template #pageHeader>
      <div class="search-form isheader" v-if="headerShow">
        <div>
          <a-form style="width: 100% !important" size="small" :model="queryData" layout="inline">
            <a-form-item
              label="坯布编号"
              v-if="
                permissionStore.hasPermisson('pblb.dclcx') ||
                permissionStore.hasPermisson('pblb.yclcx')
              "
            >
              <a-input
                allow-clear
                :style="{ width: '200px' }"
                class="bacClass"
                placeholder=""
                v-model="pageData.dropDownData"
                @press-enter="huiche"
              />
            </a-form-item>
            <a-form-item
              label="坯布名称"
              v-if="
                permissionStore.hasPermisson('pblb.dclcx') ||
                permissionStore.hasPermisson('pblb.yclcx')
              "
            >
              <a-input
                allow-clear
                :style="{ width: '200px' }"
                class="bacClass"
                placeholder=""
                v-model="pageData.dropDownData2"
                @press-enter="huiche"
              />
            </a-form-item>
            <!--            <a-form-item label="产品类型" v-if="permissionStore.hasPermisson('pblb.dclcx') ||-->
            <!--              permissionStore.hasPermisson('pblb.yclcx')-->
            <!--              ">-->
            <!--              <a-input allow-clear :style="{ width: '200px' }" class="bacClass" placeholder=""-->
            <!--                v-model="pageData.dropDownData4" @press-enter="huiche" />-->
            <!--            </a-form-item>-->
          </a-form>
        </div>
        <div class="my-tool-bar">
          <Toolbar
            v-if="shenhebiaoji == 1"
            :items="[
              `${permissionStore.hasPermisson('pblb.dclcx') ? '查询' : ''}`,
              `${permissionStore.hasPermisson('pblb.dclxz') ? '新增' : ''}`,
              `${permissionStore.hasPermisson('pblb.dclsc') ? '删除' : ''}`,
              `${permissionStore.hasPermisson('pblb.dclsh') ? '审核' : ''}`,
            ]"
            @add="addHandler"
            @del="deleteHandler"
            @select="selectHandler"
            @audit="shenhe('待审核')"
          >
          </Toolbar>
          <a-dropdown trigger="hover" popup-container="html">
            <Toolbar
              v-if="shenhebiaoji == 1"
              :items="[`${permissionStore.hasPermisson('pblb.dclfz') ? '复制' : ''}`]"
              @copy="wdfz"
            >
            </Toolbar>
            <template #content>
              <a-doption @click="fuzhixinzeng('工艺')">工艺</a-doption>
              <a-doption @click="fuzhixinzeng('颜色')">颜色</a-doption>
              <a-doption @click="fuzhixinzeng('工艺颜色')">工艺颜色</a-doption>
            </template>
          </a-dropdown>

          <Toolbar
            v-if="shenhebiaoji == 2"
            :items="[
              `${permissionStore.hasPermisson('pblb.yclcx') ? '查询' : ''}`,
              `${permissionStore.hasPermisson('pblb.yclxz') ? '新增' : ''}`,
              `${permissionStore.hasPermisson('pblb.yclsc') ? '删除' : ''}`,
              `${permissionStore.hasPermisson('pblb.yclfs') ? '反审' : ''}`,
            ]"
            @add="addHandler"
            @del="deleteHandler"
            @select="selectHandler"
            @counter="shenhe('已审核')"
          >
          </Toolbar>
          <a-dropdown trigger="hover" popup-container="html">
            <Toolbar
              v-if="shenhebiaoji == 2"
              :items="[`${permissionStore.hasPermisson('pblb.yclfz') ? '复制' : ''}`]"
              @copy="wdfz"
            >
            </Toolbar>
            <template #content>
              <a-doption @click="fuzhixinzeng('工艺')">工艺</a-doption>
              <a-doption @click="fuzhixinzeng('颜色')">颜色</a-doption>
              <a-doption @click="fuzhixinzeng('工艺颜色')">工艺颜色</a-doption>
            </template>
          </a-dropdown>
        </div>
      </div>
      <div class="my-divisders">
        <a-divider orientation="center">
          <icon-double-up
            v-if="headerShow"
            @click="headerShow = false"
            :strokeWidth="2"
            :size="18"
          />
          <icon-double-down v-else @click="headerShow = true" :strokeWidth="2" :size="18" />
        </a-divider>
      </div>
    </template>

    <template #pageTabel>
      <a-tabs :lazy-load="true" :justify="true" default-active-key="1" @change="handoff">
        <a-tab-pane title="待审核" key="1">
          <a-spin
            :loading="pageData.pageLoading"
            tip="加载中"
            dot
            style="height: 100%; width: 100%; z-index: 999"
          >
            <div style="width: 100%; height: 100%">
              <encapsulation-agrid
                ref="table1Ref"
                :configaggrid="configTable1"
                @update:listData="getTable1Data"
              ></encapsulation-agrid>
            </div>
          </a-spin>
        </a-tab-pane>

        <a-tab-pane title="已审核" key="2">
          <a-spin
            :loading="pageData.pageLoading"
            tip="加载中"
            dot
            style="height: 100%; width: 100%; z-index: 999"
          >
            <div style="width: 100%; height: 100%">
              <encapsulation-agrid
                ref="table2Ref"
                :configaggrid="configTable2"
                @update:listData="getTable2Data"
              ></encapsulation-agrid>
            </div>
          </a-spin>
        </a-tab-pane>
      </a-tabs>
    </template>
    <a-drawer
      ok-text="保存"
      cancel-text="关闭"
      :style="{ zIndex: 999 }"
      :mask-closable="false"
      :ok-loading="pageData.pageLoading"
      unmount-on-close
      popup-container=".arco-tabs-content"
      height="100%"
      :visible="pageData.showAdd2"
      placement="bottom"
      @cancel="handleDrawerCancel"
    >
      <template #title>
        {{ pageData.isDetails == true ? '详情' : pageData.sideTitle }}
      </template>
      <!-- 基本信息 -->
      <template #footer>
        <a-button @click="cancelPop"> 关闭</a-button>
        <a-button type="primary" @click="sideOk" v-if="!pageData.isDetails"> 保存</a-button>
      </template>
      <div style="min-width: 1500px; overflow: auto" class="scrollbar">
        <el-scrollbar>
          <a-collapse :default-active-key="[1, 2]">
            <a-collapse-item header="基本信息" :key="1">
              <a-form
                style="padding-left: 40px"
                size="mini"
                ref="formRef"
                layout="inline"
                :model="dataForm"
              >
                <a-form-item
                  v-if="pageData.sideTitle != '复制新增'"
                  :style="{ width: '325px' }"
                  label-col-flex="100px"
                  label="坯布编号"
                  field="greyCode"
                  :disabled="
                    dataForm.processType == 0 && pageData.isDetails == false ? true : false
                  "
                >
                  <a-input
                    :class="{ bacClass: true }"
                    :disabled="pageData.isDetails"
                    :style="{ width: '250px' }"
                    v-model="dataForm.greyCode"
                  ></a-input>
                </a-form-item>
                <a-form-item
                  v-else
                  :style="{ width: '325px' }"
                  label-col-flex="100px"
                  label="坯布编号"
                  field="greyCode"
                >
                  <a-input
                    :class="{ bacClass: true }"
                    :style="{ width: '250px' }"
                    v-model="dataForm.greyCode"
                  ></a-input>
                </a-form-item>

                <a-form-item
                  :style="{ width: '325px' }"
                  label-col-flex="100px"
                  label="是否本集团"
                  field="processType"
                  :disabled="pageData.isDetails"
                  :rules="[{ required: true, message: '是否本集团必选' }]"
                  :validate-trigger="['change', 'blur']"
                >
                  <a-select
                    popup-container="html"
                    :style="{ width: '250px' }"
                    :class="{ bacClass: true }"
                    disabled
                    v-model="dataForm.processType"
                    @change="codeGen"
                  >
                    <a-option :value="0">本集团</a-option>
                    <a-option :value="1">外加工</a-option>
                  </a-select>
                </a-form-item>

                <a-form-item
                  :style="{ width: '325px' }"
                  label-col-flex="120px"
                  label="坯布功能位代号"
                  field="feature"
                  :disabled="pageData.isDetails"
                  :rules="[{ required: true, message: '功能必选' }]"
                >
                  <a-select
                    popup-container="html"
                    :class="{ bacClass: true }"
                    @change="codeGen"
                    v-model="dataForm.feature"
                    allow-clear
                    allow-search
                    @search="gnSelect"
                    @focus="focusGn"
                  >
                    <a-option v-for="item in gnList" :value="item.greyInformationName">
                      {{ item.greyInformationName }}
                    </a-option>
                  </a-select>
                </a-form-item>

                <a-form-item
                  :style="{ width: '325px' }"
                  label-col-flex="100px"
                  label="纱线类别"
                  field="yarnCountCategory"
                  :disabled="pageData.isDetails"
                  :rules="[{ required: true, message: '纱线类别必选' }]"
                >
                  <a-select
                    popup-container="html"
                    :class="{ bacClass: true }"
                    @change="codeGen"
                    allow-search
                    allow-clear
                    @search="szSelect"
                    @focus="szSelect"
                    v-model="dataForm.yarnCountCategory"
                  >
                    <a-option v-for="item in szList" :value="item.yarnName"
                      >{{ item.yarnName }}
                    </a-option>
                  </a-select>
                </a-form-item>

                <a-form-item
                  :style="{ width: '1372px' }"
                  label-col-flex="100px"
                  label="坯布名称"
                  field="grayFabricName"
                  :disabled="pageData.isDetails"
                  :rules="[{ required: true, message: '坯布名称必填' }]"
                  :validate-trigger="['change', 'blur']"
                >
                  <a-input :class="{ bacClass: true }" v-model="dataForm.grayFabricName" />
                </a-form-item>

                <a-form-item
                  :style="{ width: '325px' }"
                  label-col-flex="100px"
                  label="布类"
                  field="mercery"
                  :rules="[{ required: true, message: '布类必选' }]"
                  :disabled="pageData.isDetails"
                >
                  <a-select
                    popup-container="html"
                    :class="{ bacClass: true }"
                    @change="codeGen"
                    allow-clear
                    allow-search
                    @search="blSelect"
                    v-model="dataForm.mercery"
                    @focus="focusBl"
                  >
                    <a-option v-for="item in blList" :value="item.merceryName"
                      >{{ item.merceryName }}
                    </a-option>
                  </a-select>
                </a-form-item>

                <a-form-item
                  :style="{ width: '325px' }"
                  label-col-flex="100px"
                  label="英文名称"
                  field="englishName"
                  :disabled="pageData.isDetails"
                >
                  <a-input :class="{ bacClass: true }" v-model="dataForm.englishName" />
                </a-form-item>

                <a-form-item
                  :style="{ width: '325px' }"
                  label-col-flex="100px"
                  label="开发编号"
                  field="exploitCode"
                  :rules="[{ validator: ExploitCodeRules }]"
                  :disabled="pageData.isDetails"
                  :validate-trigger="['change', 'blur']"
                >
                  <a-input :class="{ bacClass: true }" v-model="dataForm.exploitCode" />
                </a-form-item>

                <a-form-item
                  :style="{ width: '325px' }"
                  label-col-flex="100px"
                  label="备案编号"
                  field="putOnRecordsCode"
                  :disabled="pageData.isDetails"
                  :rules="[{ validator: putOnRecordsCodeRules }]"
                  :validate-trigger="['change', 'blur']"
                >
                  <a-input :class="{ bacClass: true }" v-model="dataForm.putOnRecordsCode" />
                </a-form-item>
                <a-form-item
                  :style="{ width: '325px' }"
                  label-col-flex="100px"
                  label="是否抽针"
                  field="drawnNeedleState"
                  :disabled="pageData.isDetails"
                  :rules="[{ required: true, message: '是否抽针必填' }]"
                  :validate-trigger="['change', 'blur']"
                >
                  <a-select
                    popup-container="html"
                    :class="{ bacClass: true }"
                    v-model="dataForm.drawnNeedleState"
                    allowClear
                  >
                    <a-option :value="0">抽针</a-option>
                    <a-option :value="1">圆筒</a-option>
                  </a-select>
                </a-form-item>

                <a-form-item
                  :style="{ width: '325px' }"
                  label-col-flex="100px"
                  label="是否开幅"
                  field="scutchingState"
                  :disabled="pageData.isDetails"
                  :rules="[{ required: true, message: '是否开幅必填' }]"
                  :validate-trigger="['change', 'blur']"
                >
                  <a-select
                    popup-container="html"
                    :class="{ bacClass: true }"
                    v-model="dataForm.scutchingState"
                    allowClear
                  >
                    <!-- <a-option value="2"> </a-option> -->
                    <a-option value="0">不开幅</a-option>
                    <a-option value="1">开幅</a-option>
                  </a-select>
                </a-form-item>

                <a-form-item
                  :style="{ width: '325px' }"
                  label-col-flex="100px"
                  label="成分"
                  field="ingredient"
                  :disabled="pageData.isDetails"
                >
                  <a-input :class="{ bacClass: true }" v-model="dataForm.ingredient" />
                </a-form-item>
                <a-form-item
                  :rules="[{ required: true, message: '加工单价必填' }]"
                  :style="{ width: '325px' }"
                  label-col-flex="100px"
                  label="加工单价"
                  :disabled="pageData.isDetails"
                >
                  <a-input-number
                    :class="{ bacClass: true }"
                    v-model="dataForm.machineUnit"
                    class="input-demo"
                    :min="0"
                    :max="10000000000000"
                    :precision="2"
                  />
                </a-form-item>

                <a-form-item
                  :style="{ width: '325px' }"
                  label-col-flex="100px"
                  label="英文成分"
                  field="englishIngredient"
                  :disabled="pageData.isDetails"
                >
                  <a-input :class="{ bacClass: true }" v-model="dataForm.englishIngredient" />
                </a-form-item>
                <a-form-item
                  :style="{ width: '325px' }"
                  label-col-flex="100px"
                  label="产品日期"
                  field="productTime"
                  :disabled="pageData.isDetails"
                >
                  <a-date-picker
                    popup-container="html"
                    :class="{ bacClass: true }"
                    style="width: 300px"
                    v-model="dataForm.productTime"
                  />
                </a-form-item>

                <a-form-item
                  :style="{ width: '325px' }"
                  label-col-flex="100px"
                  label="面料种类"
                  field="fabricType"
                  :disabled="pageData.isDetails"
                >
                  <a-select
                    popup-container="html"
                    :class="{ bacClass: true }"
                    allow-clear
                    allow-search
                    @search="fabricTypeSelect"
                    v-model="dataForm.fabricType"
                    @focus="fabricTypeFocus"
                  >
                    <a-option v-for="item in fabricTypeList" :value="item.fabricType">
                      {{ item.fabricType }}
                    </a-option>
                  </a-select>
                </a-form-item>
                <a-form-item
                  :style="{ width: '325px' }"
                  label-col-flex="100px"
                  label="坯布组织"
                  field="organization"
                  :disabled="pageData.isDetails"
                  :rules="[{ required: true, message: '坯布组织必选' }]"
                >
                  <a-select
                    popup-container="html"
                    :class="{ bacClass: true }"
                    :loading="loading"
                    v-model="dataForm.organization"
                    :filter-option="false"
                    allow-search
                    allow-clear
                    @focus="focusSel6"
                    @search="handleSearch6"
                  >
                    <a-option v-for="item in pageData.zuzhiList" :value="item.categoryName"
                      >{{ item.categoryName }}
                    </a-option>
                  </a-select>
                </a-form-item>
                <a-form-item
                  :style="{ width: '325px' }"
                  label-col-flex="100px"
                  label="成品门幅"
                  field="finishedLimit"
                  :disabled="pageData.isDetails"
                >
                  <a-input :class="{ bacClass: true }" v-model="dataForm.finishedLimit" />
                </a-form-item>

                <a-form-item
                  :style="{ width: '325px' }"
                  label-col-flex="100px"
                  label="成品克重"
                  field="finishedWeight"
                  :disabled="pageData.isDetails"
                >
                  <a-input :class="{ bacClass: true }" v-model="dataForm.finishedWeight" />
                </a-form-item>
              </a-form>
            </a-collapse-item>
            <!-- 工艺信息 -->
            <a-collapse-item header="工艺信息" :key="2">
              <a-form
                style="padding-left: 40px"
                size="mini"
                ref="formRef1"
                layout="inline"
                :model="dataForm"
              >
                <a-form-item
                  :style="{ width: '325px' }"
                  label-col-flex="100px"
                  label="设备机型"
                  field="machineType"
                  :disabled="pageData.isDetails"
                  :rules="[{ required: true, message: '设备机型必填' }]"
                  :validate-trigger="['change', 'blur']"
                >
                  <a-select
                    popup-container="html"
                    :class="{ bacClass: true }"
                    v-model="dataForm.machineType"
                    @search="searchMachineTypeList"
                    :filter-option="false"
                    allow-search
                    allow-clear
                    @focus="focusMachineTypeList"
                    @change="jixing"
                    @blur="blurJx"
                  >
                    <a-option v-for="item in pageData.machineTypeList" :value="item.typeName">
                      {{ item.typeName }}
                    </a-option>
                  </a-select>
                </a-form-item>
                <a-form-item
                  :style="{ width: '325px' }"
                  label-col-flex="100px"
                  label="订单机型"
                  field="orderMachineType"
                  :disabled="pageData.isDetails"
                  :rules="[{ required: true, message: '订单机型必填' }]"
                  :validate-trigger="['change', 'blur']"
                >
                  <a-select
                    popup-container="html"
                    :class="{ bacClass: true }"
                    v-model="dataForm.orderMachineType"
                    @click="ddjxClick"
                    :filter-option="false"
                    allow-search
                    allow-clear
                  >
                    <a-option v-for="item in ddjxList" :value="item.detailName">
                      {{ item.detailName }}
                    </a-option>
                  </a-select>
                </a-form-item>
                <a-form-item
                  :style="{ width: '325px' }"
                  label-col-flex="100px"
                  label="实际产量"
                  :disabled="pageData.isDetails"
                >
                  <a-input-number
                    :class="{ bacClass: true }"
                    v-model="dataForm.activeOutput"
                    class="input-demo"
                    :min="0"
                    :max="10000000"
                    :precision="2"
                  />
                </a-form-item>
                <a-form-item
                  :style="{ width: '325px' }"
                  label-col-flex="100px"
                  label="理论产量"
                  field="theoreticalYield"
                  disabled
                  :rules="[{ required: true, message: '理论产量必填' }]"
                  :validate-trigger="['change', 'blur']"
                >
                  <a-input-number
                    :class="{ bacClass: true }"
                    v-model="dataForm.theoreticalYield"
                    class="input-demo"
                    :min="1"
                    :max="10000000"
                  />
                </a-form-item>
                <a-form-item
                  :style="{ width: '325px' }"
                  label-col-flex="100px"
                  label="理论单价"
                  :disabled="pageData.isDetails"
                >
                  <a-input-number
                    v-model="theoryPrice"
                    :min="1"
                    :max="10000000"
                    :class="{ bacClass: true }"
                    :precision="2"
                  />
                </a-form-item>
                <a-form-item
                  :style="{ width: '325px' }"
                  label-col-flex="100px"
                  label="寸数"
                  field="dimensionFigure"
                  :rules="[{ required: true, message: '寸数必填' }]"
                  :disabled="pageData.isDetails"
                >
                  <a-select
                    popup-container="html"
                    :class="{ bacClass: true }"
                    v-model="dataForm.dimensionFigure"
                    @search="searchNeedleCountList"
                    :filter-option="false"
                    allow-search
                    allow-clear
                    @change="changeNeedleCount"
                    @focus="focusNeedleCountList"
                  >
                    <a-option v-for="item in pageData.needleCountList" :value="item['model']"
                      >{{ item['model'] }}
                    </a-option>
                  </a-select>
                </a-form-item>
                <a-form-item
                  :style="{ width: '325px' }"
                  label-col-flex="100px"
                  label="针数"
                  field="needleCount"
                  :disabled="pageData.isDetails"
                  :rules="[{ required: true, message: '针数必填' }]"
                >
                  <a-input v-model="dataForm.needleCount" :class="{ bacClass: true }" disabled />
                </a-form-item>

                <a-form-item
                  :style="{ width: '325px' }"
                  label-col-flex="100px"
                  label="总针数"
                  field="sumNeedleCount"
                  :disabled="pageData.isDetails"
                  :rules="[{ required: true, message: '总针数必填' }]"
                >
                  <a-input v-model="dataForm.sumNeedleCount" :class="{ bacClass: true }" disabled />
                </a-form-item>

                <a-form-item
                  :style="{ width: '325px' }"
                  label-col-flex="100px"
                  label="总路数"
                  field="alwaysGoes"
                  :disabled="pageData.isDetails"
                  :rules="[{ required: true, message: '总路数必填' }]"
                  :validate-trigger="['change', 'blur']"
                >
                  <!-- <a-input-number :class="{ bacClass: true }" v-model="dataForm.alwaysGoes" class="input-demo" :min="1"
                    :max="10000000" :precision="0" /> -->
                  <a-select
                    popup-container="html"
                    class="bacClass"
                    v-model="dataForm.alwaysGoes"
                    allow-clear
                    @click="zlsClick"
                    :disabled="!dataForm.dimensionFigure || !dataForm.orderMachineType"
                  >
                    <a-option v-for="item in zlsList" :value="item.totalWayCount">
                      {{ item.totalWayCount }}
                    </a-option>
                  </a-select>
                </a-form-item>
                <a-form-item
                  :style="{ width: '325px' }"
                  label-col-flex="100px"
                  label="颜色属性"
                  field="colorAttribute"
                  :disabled="pageData.isDetails"
                  :rules="[{ required: true, message: '颜色属性必选' }]"
                >
                  <a-select
                    popup-container="html"
                    :class="{ bacClass: true }"
                    v-model="dataForm.colorAttribute"
                    @search="searchColorAttribute"
                    :filter-option="false"
                    allow-search
                    allow-clear
                    @focus="focusColorAttribute"
                  >
                    <a-option
                      v-for="item in pageData.colorAttributeList"
                      :value="item['colorattribute']"
                      >{{ item['colorattribute'] }}
                    </a-option>
                  </a-select>
                </a-form-item>

                <a-form-item
                  :style="{ width: '325px' }"
                  label-col-flex="100px"
                  label="织机转速"
                  field="loomRevolution"
                  :disabled="pageData.isDetails"
                  :rules="[{ required: true, message: '织机转速必选' }]"
                >
                  <a-input-number
                    :class="{ bacClass: true }"
                    v-model="dataForm.loomRevolution"
                    class="input-demo"
                    :min="1"
                    :max="10000000"
                    @change="getTheoreticalYield('')"
                    :precision="2"
                  />
                </a-form-item>

                <a-form-item
                  :style="{ width: '325px' }"
                  label-col-flex="100px"
                  label="循环间距"
                  field="circulationGap"
                  :disabled="pageData.isDetails"
                >
                  <a-input :class="{ bacClass: true }" v-model="dataForm.circulationGap" />
                </a-form-item>

                <a-form-item
                  :style="{ width: '325px' }"
                  label-col-flex="100px"
                  label="胶管名称"
                  field="rubberTube"
                  :disabled="pageData.isDetails"
                >
                  <a-select
                    popup-container="html"
                    :class="{ bacClass: true }"
                    allow-clear
                    v-model="dataForm.rubberTube"
                    allow-search
                    @focus="focusJgCx"
                    @search="jgCx"
                  >
                    <a-option v-for="item in jgCxArray">{{ item.rubberhoseName }}</a-option>
                  </a-select>
                </a-form-item>
                <a-form-item
                  :style="{ width: '325px' }"
                  label-col-flex="100px"
                  label="主推商品"
                  field="popularizeCommodity"
                  :disabled="pageData.isDetails"
                >
                  <a-input
                    :class="{ bacClass: true }"
                    placeholder=""
                    v-model="dataForm.popularizeCommodity"
                  />
                </a-form-item>

                <a-form-item
                  :style="{ width: '325px' }"
                  label-col-flex="100px"
                  label="纱长"
                  field="yarnLength"
                  disabled
                >
                  <a-input
                    :class="{ bacClass: true }"
                    placeholder=""
                    v-model="dataForm.yarnLength"
                  />
                </a-form-item>
                <a-form-item
                  :style="{ width: '325px' }"
                  label-col-flex="100px"
                  label="库存分机台"
                  field="differentiateState"
                  :disabled="pageData.isDetails"
                >
                  <a-checkbox v-model="isChecked"> </a-checkbox>
                </a-form-item>
                <a-form-item
                  :style="{ width: '1372px' }"
                  label-col-flex="100px"
                  label="织造备注"
                  field="weavingNote"
                  :disabled="pageData.isDetails"
                >
                  <a-textarea
                    :class="{ bacClass: true }"
                    placeholder=""
                    v-model="dataForm.weavingNote"
                    :max-length="400"
                    allow-clear
                    show-word-limit
                  />
                </a-form-item>
              </a-form>
            </a-collapse-item>
          </a-collapse>
          <!-- 成分 -->
          <a-tabs :lazy-load="true" @change="gaibian">
            <a-tab-pane key="1" title="纱支结构">
              <a-space direction="vertical" fill>
                <a-form :model="{}" layout="inline" :disabled="pageData.isDetails">
                  <a-form-item v-if="!pageData.isDetails">
                    <a-button
                      @click="handleClick1"
                      type="primary"
                      size="mini"
                      style="margin-right: 10px"
                      >选择原料
                    </a-button>
                    <a-button @click="delYl" type="primary" status="danger" size="mini"
                      >删除
                    </a-button>
                  </a-form-item>
                </a-form>
                <a-table
                  :style="{ height: '400px' }"
                  stripe
                  :bordered="true"
                  :columns="tableColumns1"
                  size="mini"
                  :row-selection="{ showCheckedAll: true, width: 50 }"
                  v-model:selected-keys="selectedRowKeys"
                  :loading="table.tableLoading"
                  :data="ylTableList"
                  :pagination="pagination"
                  rowKey="yarnSource"
                >
                  <template #yarnSource="{ record }">
                    <a-input
                      :class="{ bacClass: true }"
                      v-model="record.yarnSource"
                      @change="changeYarnSource(record)"
                      @input="tongbupaisha(record)"
                      :disabled="pageData.isDetails"
                    />
                  </template>
                  <template #yarnCode="{ record }">
                    <a-input
                      :class="{ bacClass: true }"
                      v-model="record.yarnCode"
                      :disabled="pageData.isDetails"
                    />
                  </template>
                  <template #staple="{ record }">
                    <a-input
                      :class="{ bacClass: true }"
                      v-model="record.staple"
                      :disabled="pageData.isDetails"
                    />
                  </template>
                  <template #stockNature="{ record }">
                    <a-input
                      :class="{ bacClass: true }"
                      v-model="record.stockNature"
                      :disabled="pageData.isDetails"
                    />
                  </template>
                  <template #sYarnProperty="{ record }">
                    <a-input
                      :class="{ bacClass: true }"
                      v-model="record.sYarnProperty"
                      :disabled="pageData.isDetails"
                    />
                  </template>
                  <template #yarnCount="{ record }">
                    <a-input
                      :class="{ bacClass: true }"
                      v-model="record.yarnCount"
                      :disabled="pageData.isDetails"
                    />
                  </template>
                  <template #yarnType="{ record }">
                    <a-input
                      :class="{ bacClass: true }"
                      v-model="record.yarnType"
                      :disabled="pageData.isDetails"
                    />
                  </template>

                  <template #danielCoefficient="{ record }">
                    <a-input
                      :class="{ bacClass: true }"
                      v-model="record.danielCoefficient"
                      @change="getTheoreticalYield(record)"
                      :disabled="pageData.isDetails"
                    />
                  </template>
                  <template #yarnCountProportion="{ record }">
                    <a-input-number
                      :class="{ bacClass: true }"
                      v-model="record.yarnCountProportion"
                      class="input-demo"
                      style="background-color: rgb(255, 122, 117) !important"
                      @change="totalOnehundred(record, 'yarnCountProportion')"
                      :disabled="pageData.isDetails"
                      :min="0"
                      :max="100"
                      :step="0.01"
                      :precision="0"
                    />
                  </template>
                  <template #actualYarn="{ record }">
                    <a-input-number
                      :class="{ bacClass: true }"
                      v-model="record.actualYarn"
                      class="input-demo"
                      :disabled="pageData.isDetails"
                      :min="0"
                      :max="100"
                      @change="totalOnehundred(record, 'actualYarn')"
                      @blur="zhongAndYin(record.actualYarn, record)"
                      :precision="2"
                    />
                  </template>
                  <template #weavingDamage="{ record }">
                    <a-input-number
                      :class="{ bacClass: true }"
                      v-model="record.weavingDamage"
                      class="input-demo"
                      style="background-color: rgb(255, 122, 117) !important"
                      :disabled="pageData.isDetails"
                      :step="0.01"
                      :precision="0"
                    />
                  </template>
                  <template #colorGroup="{ record }">
                    <a-input
                      :class="{ bacClass: true }"
                      v-model="record.colorGroup"
                      :disabled="pageData.isDetails"
                      @change="isEng(record, record.colorGroup)"
                    />
                  </template>
                  <template #circularSpacing="{ record }">
                    <a-input-number
                      :class="{ bacClass: true }"
                      v-model="record.circularSpacing"
                      :disabled="pageData.isDetails"
                    />
                  </template>
                  <template #yarnLong="{ record }">
                    <a-input-number
                      :class="{ bacClass: true }"
                      v-model="record.yarnLong"
                      :disabled="pageData.isDetails"
                      style="background-color: rgb(255, 122, 117) !important"
                      @change="getTheoreticalYield(record)"
                      :step="0.01"
                      :precision="0"
                      @blur="YarnLengthRule"
                      hide-button
                    />
                  </template>
                  <template #wayNum="{ record }">
                    <a-input-number
                      :class="{ bacClass: true }"
                      v-model="record.wayNum"
                      :disabled="pageData.isDetails"
                      style="background-color: rgb(255, 122, 117) !important"
                      @change="getTheoreticalYield(record)"
                      :step="1"
                      :precision="0"
                      hide-button
                    />
                  </template>
                  <template #yarnUnits="{ record }">
                    <a-select
                      popup-container="html"
                      :disabled="pageData.isDetails"
                      :class="{ bacClass: true }"
                      v-model="record.yarnUnits"
                      @focus="getYarnUnitsList"
                      allow-clear
                      @change="getTheoreticalYield(record)"
                      style="background-color: rgb(255, 122, 117) !important"
                    >
                      <a-option
                        v-for="(item, index) in pageData.yarnUnitsList"
                        :value="item['detailName']"
                        >{{ item['detailName'] }}
                      </a-option>
                    </a-select>
                  </template>

                  <template #colourNumber="{ record }">
                    <!-- <a-select popup-container="html" :disabled="pageData.isDetails" :class="{ bacClass: true }"
                      v-model="record.colourNumber" :filter-option="false" allow-search allow-clear
                      @focus="getcolornumber('色号')">
                      <a-option @click="fuzhixiala({ val: '色号', item, record })" v-for="item in colornumberlist"
                        :value="item['colourNumber']">{{ item['colorNumber'] }}
                      </a-option>
                    </a-select> -->
                    <div @dblclick="colourNumberClick(record)">
                      <a-input
                        :class="{ bacClass: true }"
                        v-model="record.colourNumber"
                        readonly
                        allow-clear
                        @clear="colourNumberClear(record)"
                      />
                    </div>
                  </template>

                  <template #colorAccording="{ record }">
                    <a-input :class="{ bacClass: true }" v-model="record.colorAccording" disabled />
                  </template>
                  <template #grade="{ record }">
                    <a-select
                      popup-container="html"
                      :disabled="pageData.isDetails"
                      :class="{ bacClass: true }"
                      v-model="record.grade"
                      :filter-option="false"
                      allow-search
                      allow-clear
                      @focus="getcolornumber('等级')"
                    >
                      <a-option
                        @click="fuzhixiala({ val: '等级', item })"
                        v-for="item in dengjilist"
                        :value="item['grade']"
                        >{{ item['levelName'] }}
                      </a-option>
                    </a-select>
                  </template>
                  <template #yujing="{ record }">
                    <a-tag checkable color="green" :default-checked="true" v-if="record.jieguo == 1"
                      >否
                    </a-tag>
                    <a-tag checkable color="red" :default-checked="true" v-if="record.jieguo == 2"
                      >是
                    </a-tag>
                  </template>
                </a-table>
              </a-space>
            </a-tab-pane>
            <a-tab-pane key="2" title="排针">
              <a-space v-if="!pageData.isDetails">
                <a-select
                  popup-container="html"
                  :class="{ bacClass: true }"
                  style="width: 150px"
                  @search="zzpzSelectType"
                  @click="zzpzSelectType('')"
                  allow-search
                  allow-clear
                  v-model="zzpzid"
                >
                  <a-option v-for="item in zzpzListSelect" :value="item.id"
                    >{{ item.organizationName }}
                  </a-option>
                </a-select>
                <a-button size="mini" @click="zzpzok" type="primary">选择组织排针</a-button>
              </a-space>
              <div style="height: 10px"></div>
              <a-space direction="vertical" fill>
                <a-space v-if="!pageData.isDetails">
                  <span>设置排针列数</span>
                  <a-input-number
                    v-model="colNumber"
                    style="width: 100px; border: 1px solid black"
                    :min="1"
                    :max="999"
                    :step="1"
                    :precision="0"
                  >
                  </a-input-number>
                  <a-checkbox-group
                    v-model="alignState"
                    :options="alignStateOptions"
                    @change="alignStateChange"
                  />
                  <a-button size="mini" type="primary" @click="addZhen">确定</a-button>
                </a-space>
                <div style="width: 100%; overflow: auto">
                  <div style="white-space: nowrap">
                    <span
                      style="padding: 5px"
                      v-if="dataForm.machineType != '单面机'"
                      :style="{'margin-right': alignType == '3' ? '7.5px':'' , }"
                      >上排</span
                    >
                    <span style="padding: 5px" v-else>排针</span>
                    <input
                      @keyup="setNum(item)"
                      v-for="(item, index) in zzpzdata"
                      :key="index"
                      style="
                        width: 30px;
                        border: 1px solid black;
                        padding: 5px;
                        text-align: center;
                        text-indent: 0;
                      "
                      :class="{ bacClass: true }"
                      v-model="item.upBasin"
                      :disabled="pageData.isDetails"
                    />
                  </div>
                  <div style="white-space: nowrap" v-if="dataForm.machineType != '单面机'">
                    <span
                      style="padding: 5px"
                      :style="{
                        'padding-right': dataForm.machineType == '螺纹机' ? '35px' : '5px',
                        'margin-right': alignType == '1' ? '15px' : (alignType == '2' ? '7.5px':''),
                      }"
                      >下排</span
                    >

                    <input
                      @keyup="setNum1(item)"
                      v-for="(item, index) in zzpzdata"
                      :key="index"
                      :class="{ bacClass: true }"
                      style="
                        width: 30px;
                        border: 1px solid black;
                        padding: 5px;
                        text-align: center;
                        text-indent: 0;
                      "
                      v-model="item.belowBasin"
                      :disabled="pageData.isDetails"
                    />
                  </div>
                </div>
              </a-space>

              <a-divider />
              <div>
                <a-select
                  popup-container="html"
                  :class="{ bacClass: true }"
                  size="mini"
                  v-model="ckpzid"
                  @search="ckpzSelect"
                  @focus="ckpzfocus"
                  allow-search
                  allow-clear
                  :style="{ width: '150px' }"
                  :disabled="pageData.isDetails"
                >
                  <a-option v-for="item in ckpzSelectList" :key="item.id" :value="item.id">
                    {{ item.cmdName }}
                  </a-option>
                </a-select>
                <a-button @click="ckpzadd" status="success" size="mini" v-if="!pageData.isDetails"
                  >选择裁口排针
                </a-button>
                <div style="display: flex; align-items: center">
                  <div style="width: 50%">
                    <span>裁口排针</span>
                    <a-textarea
                      :class="{ bacClass: true }"
                      v-model="ckpzobj.pinHeader"
                      :disabled="pageData.isDetails"
                    >
                    </a-textarea>
                  </div>
                  <div style="width: 50%">
                    <span>纱线排列</span>
                    <a-textarea
                      :class="{ bacClass: true }"
                      v-model="ckpzobj.arrangement"
                      :disabled="pageData.isDetails"
                    >
                    </a-textarea>
                  </div>
                </div>
              </div>
            </a-tab-pane>
            <a-tab-pane key="3" title="排三角">
              <a-space v-if="!pageData.isDetails">
                <div>
                  <a-space>
                    <a-select
                      popup-container="html"
                      :class="{
                        bacClass: !pageData.isDetails,
                        'opcity-ipt': (addFlag != 3 && addFlag != 0) || addFlag == -1,
                      }"
                      allow-search
                      placeholder=""
                      v-model="sjid"
                      @search="sjSelect"
                      allow-clear
                      :style="{ width: '200px' }"
                      :disabled="(addFlag != 3 && addFlag != 0) || addFlag == -1"
                      @focus="focusSj"
                      @blur="selectPsj(2)"
                    >
                      <a-option v-for="item in sjSelectList" :value="item.id" :key="item.id">
                        {{ item.atName }}
                      </a-option>
                    </a-select>
                    <a-button
                      @click="sjOk"
                      :disabled="(addFlag != 3 && addFlag != 0) || addFlag == -1"
                      >选择排三角</a-button
                    >
                    <a-select
                      popup-container="html"
                      :class="{
                        bacClass: !pageData.isDetails,
                        'opcity-ipt': (addFlag != 4 && addFlag != 0) || addFlag == -1,
                      }"
                      @search="psjpblistSelect"
                      @focus="psjpblistSelect"
                      placeholder=""
                      allow-search
                      allow-clear
                      :disabled="(addFlag != 4 && addFlag != 0) || addFlag == -1"
                      :style="{ width: '200px' }"
                      v-model="psjpb"
                    >
                      <a-option v-for="item in psjpblist" :value="item.id"
                        >{{ item.greyCode }}
                      </a-option>
                    </a-select>
                    <a-button
                      size="mini"
                      @click="psjpbOk"
                      :type="
                        (addFlag != 4 && addFlag != 0) || addFlag == -1 ? undefined : 'outline'
                      "
                      :disabled="(addFlag != 4 && addFlag != 0) || addFlag == -1"
                      >现有坯布导入排三角</a-button
                    >
                  </a-space>
                </div>
                <a-form layout="inline" :model="dataForm">
                  <a-form-item label="设备机型">
                    <a-input
                      :disabled="true"
                      :class="{ bacClass: true }"
                      v-model="dataForm.machineType"
                    />
                  </a-form-item>
                  <a-form-item>
                    <!-- 非单面机 -->
                    <a-radio-group v-model="tagValue">
                      <a-radio v-for="item in pageData.tags" :value="item.id">
                        {{ item.val }}
                      </a-radio>
                    </a-radio-group>
                  </a-form-item>
                </a-form>
              </a-space>
              <div style="height: 20px"></div>
              <a-space v-if="sjdata.sj.length && !pageData.isDetails">
                <a-input-number
                  :class="{
                    bacClass: !pageData.isDetails,
                    'opcity-ipt': (addFlag != 1 && addFlag != 0) || addFlag == -1,
                  }"
                  :min="1"
                  :max="999"
                  size="mini"
                  @change="xunhuan('实开')"
                  @blur="YarnLengthRule"
                  v-model="numb.col"
                  :precision="0"
                  :disabled="(addFlag != 1 && addFlag != 0) || addFlag == -1"
                ></a-input-number>
                <a-button
                  size="mini"
                  :type="(addFlag != 1 && addFlag != 0) || addFlag == -1 ? undefined : 'primary'"
                  :status="addFlag == 1 ? undefined : 'success'"
                  :disabled="(addFlag != 1 && addFlag != 0) || addFlag == -1"
                  @click="xuanranpaisha"
                >
                  设置循环路数
                </a-button>
                循环次数:
                <a-input-number
                  :class="
                    {
                      bacClass: !pageData.isDetails,
                      'opcity-ipt': (addFlag != 1 && addFlag != 0) || addFlag == -1,
                    } || addFlag == -1
                  "
                  :min="1"
                  :max="999"
                  size="mini"
                  v-model="xuanhuancihu"
                  @change="xunhuan('循环')"
                  :precision="0"
                  :disabled="(addFlag != 1 && addFlag != 0) || addFlag == -1"
                ></a-input-number>
                实开路数:
                <a-input-number
                  :class="{ bacClass: !pageData.isDetails }"
                  :min="1"
                  :max="999"
                  size="mini"
                  v-model="shikaishu"
                  :disabled="true"
                ></a-input-number>
                针叶型号:
                <a-input :class="{ bacClass: !pageData.isDetails }" v-model="dataForm.needleType" />
                <a-button
                  size="mini"
                  :type="(addFlag != 2 && addFlag != 0) || addFlag == -1 ? undefined : 'primary'"
                  :status="addFlag == 1 ? undefined : 'success'"
                  @click="setLoop"
                  :disabled="(addFlag != 2 && addFlag != 0) || addFlag == -1"
                >
                  设置循环
                </a-button>
                <a-button size="mini" status="danger" @click="showwarning"> 清除 </a-button>
              </a-space>

              <div
                v-for="(item, index) in sjdata.sj as any"
                style="text-align: center; margin: 20px auto; width: 100%; overflow-x: auto"
              >
                <div
                  style="
                    text-align: center;
                    color: #165dff;
                    font-size: 16px;
                    background-color: aliceblue;
                    border-bottom: 0.5px solid #ccc;
                  "
                >
                  {{ item.type }}
                </div>

                <div
                  class="thead"
                  style="background-color: aliceblue"
                  v-if="item.typeData[0].needleList != undefined"
                >
                  <div class="th" style="width: 50px">序号</div>
                  <div class="th" style="width: 150px">用针</div>
                  <div
                    class="th"
                    style="width: 40px"
                    v-for="i2 in item.typeData[0].needleList"
                    :key="i2.way"
                  >
                    {{ i2.way }}
                  </div>
                </div>

                <div
                  class="tbody"
                  :style="{ position: 'relative', top: biaoji != 0 ? '-5px' : '' }"
                  v-for="(i1, biaoji) in item.typeData"
                  v-if="
                    item.type == '上盘' &&
                    (dataForm.machineType == '双面机' || dataForm.machineType == '螺纹机')
                  "
                >
                  <div class="td" style="width: 50px">{{ i1.serialNumber }}</div>
                  <div class="td" style="width: 150px">
                    <a-tooltip :content="i1.needleName" v-if="i1.needleName != ''">
                      <a-select
                        popup-container="html"
                        :disabled="pageData.isDetails"
                        @focus="getwuliao({ materialName: '', auditState: 1 })"
                        @search="getwuliao"
                        :class="{ bacClass: true }"
                        v-model="i1.needleName"
                        allow-search
                      >
                        <a-option v-for="item in wuliaoname" :value="item.materialName"
                          >{{ item.materialName }}
                        </a-option>
                      </a-select>
                    </a-tooltip>
                    <a-select
                      popup-container="html"
                      :disabled="pageData.isDetails"
                      @focus="getwuliao({ materialName: '', auditState: 1 })"
                      @search="getwuliao"
                      v-if="i1.needleName == ''"
                      :class="{ bacClass: true }"
                      v-model="i1.needleName"
                      allow-search
                    >
                      <a-option v-for="item in wuliaoname" :value="item.materialName"
                        >{{ item.materialName }}
                      </a-option>
                    </a-select>
                  </div>
                  <div
                    class="td"
                    style="
                      height: 34px;
                      width: 40px;
                      vertical-align: middle;
                      border: 1px solid gray;
                    "
                    v-for="i2 in i1.needleList"
                  >
                    <div
                      style="width: 100%; height: 100%"
                      class="gesture"
                      @click="setSJValue(i2, item)"
                      v-if="!pageData.isDetails"
                      >{{ pageData.tags.filter((o) => o.id === i2.needle)[0]?.val }}
                    </div>
                    <div style="width: 100%; height: 100%" v-if="pageData.isDetails"
                      >{{ pageData.tags.filter((o) => o.id === i2.needle)[0]?.val }}
                    </div>
                  </div>
                </div>
                <div
                  class="tbody"
                  :style="{ position: 'relative', top: biaoji != 0 ? '-5px' : '' }"
                  v-for="(i1, biaoji) in item.typeData"
                  v-else
                >
                  <div class="td" style="width: 50px">{{ i1.serialNumber }}</div>
                  <div class="td" style="width: 150px">
                    <a-tooltip :content="i1.needleName" v-if="i1.needleName != ''">
                      <a-select
                        popup-container="html"
                        :disabled="pageData.isDetails"
                        @focus="getwuliao({ materialName: '', auditState: 1 })"
                        @search="getwuliao"
                        :class="{ bacClass: true }"
                        v-model="i1.needleName"
                        allow-search
                      >
                        <a-option v-for="item in wuliaoname" :value="item.materialName"
                          >{{ item.materialName }}
                        </a-option>
                      </a-select>
                    </a-tooltip>
                    <a-select
                      popup-container="html"
                      :disabled="pageData.isDetails"
                      @focus="getwuliao({ materialName: '', auditState: 1 })"
                      @search="getwuliao"
                      v-if="i1.needleName == ''"
                      :class="{ bacClass: true }"
                      v-model="i1.needleName"
                      allow-search
                    >
                      <a-option v-for="item in wuliaoname" :value="item.materialName"
                        >{{ item.materialName }}
                      </a-option>
                    </a-select>
                  </div>
                  <div
                    class="td"
                    style="
                      height: 34px;
                      width: 40px;
                      vertical-align: middle;
                      border: 1px solid gray;
                    "
                    v-for="i2 in i1.needleList"
                  >
                    <div
                      style="width: 100%; height: 100%"
                      class="gesture"
                      @click="setSJValue(i2, item)"
                      v-if="!pageData.isDetails"
                      >{{ pageData.tags.filter((o) => o.id === i2.needle)[0]?.val }}
                    </div>
                    <div style="width: 100%; height: 100%" v-if="pageData.isDetails"
                      >{{ pageData.tags.filter((o) => o.id === i2.needle)[0]?.val }}
                    </div>
                  </div>
                </div>

                <div style="height: 20px"></div>
                <a-space fill v-if="!pageData.isDetails">
                  <a-input-number
                    :class="{ bacClass: !pageData.isDetails }"
                    :min="1"
                    :max="999"
                    v-model="numb.row[index]"
                    size="mini"
                  ></a-input-number>
                  <a-button @click="addRow(item)" type="primary" size="mini">设置用针</a-button>
                </a-space>
                <div style="height: 20px"></div>
                <div style="border: 1px solid #ccc"></div>
              </div>
              <!-- 排纱 numb.col列 ylTableList行+1-->
              <a-button type="primary" size="mini" @click="handleClick" v-if="!pageData.isDetails"
                >批量修改
              </a-button>
              <div class="tbody" v-if="addFlag != 2" style="margin-top: 10px; overflow: auto">
                <div
                  style="
                    text-align: center;
                    color: #165dff;
                    font-size: 16px;
                    background-color: aliceblue;
                    border-bottom: 0.5px solid #ccc;
                  "
                >
                  排纱
                </div>
                <div class="trow" style="background-color: aliceblue">
                  <div
                    style="
                      height: 30px;
                      display: inline-block;
                      width: 82px;
                      vertical-align: top;
                      box-sizing: border-box;
                    "
                  >
                  </div>
                  <div
                    style="
                      height: 30px;
                      display: inline-block;
                      width: 82px;
                      vertical-align: top;
                      box-sizing: border-box;
                    "
                  >
                  </div>

                  <div
                    v-for="(item, index) in xhCol"
                    style="
                      height: 30px;
                      display: inline-block;
                      vertical-align: top;
                      width: 82px;
                      line-height: 30px;
                    "
                  >
                    <input
                      type="checkbox"
                      :value="index"
                      @change="changeXh($event, index)"
                      :class="{ bacClass: true }"
                      class="inputCheck gesture"
                      v-if="index != 0"
                      :disabled="pageData.isDetails"
                    />
                    {{ index == 0 ? '序号' : item.val }}
                  </div>
                </div>
                <div class="trow" v-for="(item, index) in psList">
                  <div
                    style="border: 1px solid #ccc; height: 30px; box-sizing: border-box"
                    v-for="(item1, index1) in item"
                  >
                    <input
                      v-model="item1.val"
                      v-if="
                        !(
                          (index > 0 && (index1 == 0 || index1 == 1 || index1 == 2)) ||
                          (index == 0 && index1 === 2)
                        )
                      "
                      style="width: 80px; vertical-align: top; height: 100%; text-align: center"
                      @blur="getWayNum"
                      :class="{ active: index1 == 0 || index1 == 1, bacClass: true }"
                      :disabled="pageData.isDetails"
                    />
                    <select
                      :class="{ bacClass: true }"
                      v-model="item1.val"
                      v-if="index > 0 && index1 == 2"
                      style="width: 80px; vertical-align: top; height: 100%; text-align: center"
                      :disabled="pageData.isDetails"
                      @focus="focusPs"
                      @change="YarnLengthRule"
                    >
                      <option
                        v-for="(item2, index2) in pageData.psDataList"
                        :value="item2['detailName']"
                      >
                        {{ item2['detailName'] }}
                      </option>
                    </select>

                    <a-tooltip v-if="index > 0 && item1.val != '纱长(cm)'" :content="item1.text">
                      <div
                        v-if="
                          (index > 0 && (index1 == 0 || index1 == 1)) ||
                          (index == 0 && index1 === 2)
                        "
                        style="width: 80px; vertical-align: top; height: 100%; text-align: center"
                        :class="{ active: index1 == 0 || index1 == 1, bacClass: true }"
                        >{{ item1.val }}
                        <div v-if="item1.val == '' && item1.text != ''">&nbsp;&nbsp;</div>
                      </div>
                    </a-tooltip>

                    <div
                      v-if="
                        (((index > 0 && (index1 == 0 || index1 == 1)) ||
                          (index == 0 && index1 === 2)) &&
                          index == 0) ||
                        item1.val == '纱长(cm)'
                      "
                      style="width: 80px; vertical-align: top; height: 100%; text-align: center"
                      :class="{ active: index1 == 0 || index1 == 1, bacClass: true }"
                      >{{ item1.val }}
                    </div>
                  </div>
                </div>
              </div>
              <!-- 排沙设置循环渲染这个 -->
              <div class="tbody" v-else style="margin-top: 10px; overflow: auto">
                <div
                  style="
                    text-align: center;
                    color: #165dff;
                    font-size: 16px;
                    background-color: aliceblue;
                    border-bottom: 0.5px solid #ccc;
                  "
                >
                  排纱
                </div>
                <div class="trow" style="background-color: aliceblue">
                  <div
                    style="
                      height: 30px;
                      display: inline-block;
                      width: 82px;
                      vertical-align: top;
                      box-sizing: border-box;
                    "
                  >
                  </div>
                  <div
                    style="
                      height: 30px;
                      display: inline-block;
                      width: 82px;
                      vertical-align: top;
                      box-sizing: border-box;
                    "
                  >
                  </div>

                  <div
                    v-for="(item, index) in xhCol"
                    style="
                      height: 30px;
                      display: inline-block;
                      vertical-align: top;
                      width: 82px;
                      line-height: 30px;
                    "
                  >
                    <input
                      type="checkbox"
                      :value="index"
                      @change="changeXh($event, index)"
                      :class="{ bacClass: true }"
                      class="inputCheck gesture"
                      v-if="index != 0"
                      :disabled="pageData.isDetails"
                    />
                    {{ index == 0 ? '序号' : item.val }}
                  </div>
                </div>
                <div class="trow" v-for="(item, index) in psList">
                  <div
                    style="border: 1px solid #ccc; height: 30px; box-sizing: border-box"
                    v-for="(item1, index1) in item"
                  >
                    <input
                      v-model="item1.val"
                      v-if="
                        !(
                          (index > 0 && (index1 == 0 || index1 == 1 || index1 == 2)) ||
                          (index == 0 && index1 === 2)
                        )
                      "
                      style="width: 80px; vertical-align: top; height: 100%; text-align: center"
                      @blur="getWayNum"
                      :class="{ active: index1 == 0 || index1 == 1, bacClass: true }"
                      :disabled="pageData.isDetails"
                    />
                    <select
                      :class="{ bacClass: true }"
                      v-model="item1.val"
                      v-if="index > 0 && index1 == 2"
                      style="width: 80px; vertical-align: top; height: 100%; text-align: center"
                      :disabled="pageData.isDetails"
                      @focus="focusPs"
                      @change="YarnLengthRule"
                    >
                      <option
                        v-for="(item2, index2) in pageData.psDataList"
                        :value="item2['detailName']"
                      >
                        {{ item2['detailName'] }}
                      </option>
                    </select>

                    <a-tooltip v-if="index > 0 && item1.val != '纱长(cm)'" :content="item1.text">
                      <div
                        v-if="
                          (index > 0 && (index1 == 0 || index1 == 1)) ||
                          (index == 0 && index1 === 2)
                        "
                        style="width: 80px; vertical-align: top; height: 100%; text-align: center"
                        :class="{ active: index1 == 0 || index1 == 1, bacClass: true }"
                        >{{ item1.val }}
                        <div v-if="item1.val == '' && item1.text != ''">&nbsp;&nbsp;</div>
                      </div>
                    </a-tooltip>

                    <div
                      v-if="
                        (((index > 0 && (index1 == 0 || index1 == 1)) ||
                          (index == 0 && index1 === 2)) &&
                          index == 0) ||
                        item1.val == '纱长(cm)'
                      "
                      style="width: 80px; vertical-align: top; height: 100%; text-align: center"
                      :class="{ active: index1 == 0 || index1 == 1, bacClass: true }"
                      >{{ item1.val }}
                    </div>
                  </div>
                </div>
              </div>
            </a-tab-pane>

            <a-tab-pane key="6" title="关联商品">
              <a-space style="margin-bottom: 10px" v-if="!pageData.isDetails">
                <a-select
                  popup-container="html"
                  :class="{ bacClass: !pageData.isDetails }"
                  size="mini"
                  @search="spSelect"
                  v-model="sp.id"
                  allow-clear
                  allow-search
                  @focus="focusSp"
                  :style="{ width: '150px' }"
                >
                  <a-option v-for="item in spSelectList" :value="item.id"
                    >{{ item['commodityCode'] }}
                  </a-option>
                </a-select>
                <a-button type="primary" size="mini" @click="addSpRow">添加</a-button>
                <a-button type="primary" status="danger" size="mini" @click="delSpRow"
                  >删除</a-button
                >
              </a-space>
              <a-table
                stripe
                :bordered="true"
                :columns="sptablecol"
                size="mini"
                :row-selection="{ showCheckedAll: true, width: 50 }"
                v-model:selected-keys="selectedRowKeysSp"
                :loading="table.tableLoading"
                :data="pageData.spRowList"
                :pagination="false"
                :rowKey="rowKey"
              >
                <template #isban="{ record }">
                  <a-checkbox
                    @change="isBan(record)"
                    :default-checked="record.isban"
                    v-model="record.isban"
                  >
                    {{ record.isban == true ? '是' : '否' }}
                  </a-checkbox>
                </template>
              </a-table>
            </a-tab-pane>
            <a-tab-pane key="7" title="排三角(旧)">
              排三角:
              <a-textarea
                :disabled="pageData.isDetails"
                style="margin-top: 10px"
                :class="{ bacClass: true }"
                placeholder=""
                v-model="crossMemo"
                :max-length="400"
                allow-clear
                show-word-limit
              />
            </a-tab-pane>
          </a-tabs>
        </el-scrollbar>
      </div>
    </a-drawer>

    <a-modal
      v-model:visible="visible"
      title="批量修改排纱"
      @cancel="handleCancel"
      @ok="handleBeforeOk"
    >
      <a-form :model="moreEdit">
        <a-form-item v-for="(val, index) in psEditList" :field="val" :label="val">
          <a-input
            :class="{ bacClass: !pageData.isDetails }"
            v-model="moreEdit[val + '_' + index]"
          />
        </a-form-item>
      </a-form>
    </a-modal>

    <a-modal
      v-model:visible="visible1"
      title="添加原料"
      @cancel="handleCancel1"
      @ok="addYl"
      ok-text="添加"
      :width="1000"
      draggable
    >
      <a-button type="primary" @click="cxYlList" size="mini">查询</a-button>
      <a-form style="width: 100% !important" size="mini" :model="ylData" layout="inline">
        <a-form-item label="原料编号">
          <a-input :class="{ bacClass: true }" v-model="ylData.rawmaterialCode" />
        </a-form-item>
        <a-form-item label="原料名称">
          <a-input :class="{ bacClass: true }" v-model="ylData.materialsName" />
        </a-form-item>

        <a-form-item label="纱支" style="padding-left: 28px">
          <a-input :class="{ bacClass: true }" v-model="ylData.yarnCount" />
        </a-form-item>
        <a-form-item
          :style="{ width: '200px' }"
          label-col-flex="70px"
          label="是否本集团"
          field="processType"
        >
          <a-select
            popup-container="html"
            :style="{ width: '180px' }"
            :class="{ bacClass: true }"
            v-model="ylData.processType"
          >
            <a-option :value="0">本集团</a-option>
            <a-option :value="1">外加工</a-option>
          </a-select>
        </a-form-item>
      </a-form>
      <a-table
        stripe
        :bordered="true"
        :columns="ylColumns"
        size="mini"
        :row-selection="{ showCheckedAll: true, width: 50 }"
        v-model:selected-keys="selectedRowKeysAddYl"
        :loading="table.tableLoading"
        :data="pageData.ylRowList"
        :pagination="false"
        :rowKey="rowKey"
      >
        <template #processType="{ record }">
          <div>{{ record.processType == 0 ? '本集团' : '外加工' }}</div>
        </template>
      </a-table>
      <paginationCopys
        :total="fySelet4.total"
        show-total
        show-jumper
        show-page-size
        @change="PageSize4"
        @page-size-change="change4"
        style="justify-content: center; margin-top: 15px"
        :page-size="fySelet4.size"
        :current="fySelet4.page"
      />
    </a-modal>
    <a-modal
      :width="1200"
      v-model:visible="settingLoopVisible"
      :on-before-ok="settingLoopOK"
      @cancel="settingLoopVisible = false"
      :mask-closable="false"
      draggable
    >
      <template #title> 设置循环 </template>
      <div>
        <div class="flex mb-5">
          <a-button class="mr-3" type="outline" status="success" @click="loopAdd">新增</a-button>
          <a-button type="outline" status="danger" @click="loopDel">删除</a-button>
        </div>
        <div class="w-full">
          <a-table
            :columns="settingLoopColumns"
            :data="TempSettingLoopData"
            v-model:selectedKeys="settingLoopKeys"
            row-key="serialNumber"
            :row-selection="settingLoopCheckBox"
            :pagination="false"
          >
            <template #wayEnd="{ record }">
              <a-input-number
                v-model="record.wayEnd"
                :min="record.wayStart"
                @change="wayEndChange"
              />
            </template>
            <template #loopCount="{ record }">
              <a-input-number v-model="record.loopCount" :min="1" @change="loopCountChange" />
            </template>
          </a-table>
        </div>
      </div>
    </a-modal>
    <a-modal
      v-model:visible="colourNumberVisible"
      @ok="colourNumberOk"
      @cancel="colourNumberCancel"
      width="800px"
    >
      <template #title>色号色称查询</template>
      <a-spin dot :loading="colourNumberLoading" class="w-full h-full">
        <div class="flex justify-between">
          <el-form @submit.native.prevent class="flex">
            <el-form-item label="色号" prop="queryColorNumber">
              <el-input v-model="queryColorNumber" style="width: 200px" />
            </el-form-item>
            <el-form-item label="色称" prop="queryNN" class="ml-5">
              <el-input v-model="queryNN" style="width: 200px" />
            </el-form-item>
          </el-form>
          <el-button type="primary" :icon="Search" @click="colorNumberSearch">查询</el-button>
        </div>
        <div>
          <AgGridVuesCopys
            :rowHeight="33"
            :headerHeight="33"
            :suppressCopyRowsToClipboard="true"
            rowSelection="single"
            @grid-ready="CNgridReady"
            style="height: 37vh"
            :defaultColDef="defaultColDef"
            class="ag-theme-alpine"
            :rowData="colorNumberdata"
            :columnDefs="colorNumberColumns"
            :localeText="localeText1"
          >
          </AgGridVuesCopys>
        </div>
        <div class="flex justify-center"
          ><el-pagination
            small
            background
            layout="prev, pager, next"
            :total="cNpagination.total"
            v-model:current-page="cNpagination.page"
            class="mt-4"
            @current-change="colorNumberSearch"
          />
        </div>
      </a-spin>
    </a-modal>
  </pageTabelLayout>
</template>

<script lang="ts">
  import { post, get } from '@/api/http'
  import {
    useTable,
    useRowKey,
    useTableColumn,
    usePagination,
    useRowSelection,
  } from '@/hooks/table'
  import emitter from '@/hooks/useEventBus'
  import { ref, reactive, onMounted, toRefs, watch, toRaw, nextTick, computed } from 'vue'
  import Toolbar from '@/components/Toolbar.vue'
  import { Button, Form, Message, Modal } from '@arco-design/web-vue'
  import { FormInstance } from '@arco-design/web-vue/es/form'
  import { log } from 'echarts/types/src/util/log'
  
  import { localeText } from '@/api/aggridZw'
  import { pagingList } from '@/api/paging'
  import { indexOf } from 'lodash'
  import { Search } from '@element-plus/icons-vue'
  import usePermission from '@/store/modules/permission'
  import { simplifyMessages } from '@/api/messageSimplification'
  import { saveOrUpdateGridState as saveOrUpdateGridState01 } from '@/hooks/useGridState'
  import { saveOrUpdateGridState as saveOrUpdateGridState02 } from '@/hooks/useGridState'
  import buttionRender from '@/components/aggridCellRenDerer/buttionRender.vue'
  import _ from 'lodash'

  interface Firm {
    name: string
    id: number
  }

  interface RawMaterialsList {
    orderMachineType: any
    circulationGap: any
    exploitCode: string | undefined
    shipperUnits: string | undefined
    activeOutput: number | undefined
    clothKindOfName: string | undefined
    loomRevolution: number | undefined
    yarnCountCode: string | undefined
    sebificDuctName: string | undefined
    id: number | undefined | string
    starts: string | undefined
    yarnCountCategory: string | undefined
    playingCards: string | undefined
    updateName: string | undefined
    greyCode: string | undefined
    inventoryLowerLimit: string | undefined
    beadJuggle: string | undefined
    knittingNeedleType: string | undefined
    productKind: string | undefined
    unit: string | undefined
    versions: string | undefined
    associatedGoods: string | undefined
    dimensionFigure: any
    grade: string | undefined
    createName: string | undefined
    colorAccording: string | undefined
    needleType: string | undefined
    englishName: string | undefined
    weaverPrice: number
    machineUnit: any
    weavingDamage: any
    actualYarn: any
    yarnCountIngredient: string | undefined
    remark: string | undefined
    productTime: any
    measuredYarnCount: string | undefined
    fabricType: string | undefined
    alwaysGoes: number | undefined
    needleCount: any
    feature: string | undefined
    mercery: string | undefined
    sumNeedleCount: any
    colorGroup: any
    machineType: string | undefined
    deleteState: number | undefined
    outsideProcessingClient: string | undefined
    ingredient: string | undefined
    englishIngredient: string | undefined
    weavingNote: string | undefined
    chineseIngredient: string | undefined
    yarnSource: string | undefined
    staple: string | undefined
    yarnKind: string | undefined
    stockNature: string | undefined
    sYarnProperty: string | undefined
    danielCoefficient: string | undefined
    yarnCountProportion: any
    inventoryDivisionMachine: string | undefined
    colorAttribute: string | undefined
    theoryCapacity: number | undefined
    updateTime: string | undefined
    grayFabricName: string | undefined
    drawnNeedleState: any
    scutchingState: any
    putOnRecordsCode: string | undefined
    yarnCountName: string | undefined
    createTime: string | undefined
    organization: string | undefined
    commodityState: string | undefined
    category: string | undefined
    inventoryUpperLimit: string | undefined
    popularizeCommodity: string | undefined
    finishedLimit: string | undefined
    finishedWeight: string | undefined
    colourNumber: number | undefined
    models: string | undefined
    processType: number | undefined
    rubberTube: any
    checkUnits: any
    perchPrice: any
    perchUnits: any
    yarnLength: any
    theoreticalYield: any
    differentiateState: any
  }

  export default {
    name: 'EmbroideryList',
    setup() {
      const pageData = reactive<{
        gcList: Firm[]
        showAdd2: boolean
        pageLoading: boolean
        sideTitle: string
        dropDownData: any
        dropDownData1: any
        dropDownData2: any
        dropDownData3: any
        dropDownData4: any
        codeList: []
        nameList: []
        nameList1: []
        ggList: []
        flList: []
        needleCountList: any[]
        machineTypeList: any[]
        colorAttributeList: any[]
        unitList: any[]
        spRowList: any[]
        rHeight: number | undefined
        zuzhiList: any[]
        ylRowList: any[]
        materialsName: any
        rawmaterialCode: any
        yarnCount: any
        materialsNameList: any[]
        rawmaterialCodeList: any[]
        yarnCountList: any[]
        zhong: any
        yin: any
        isDetails: boolean
        cfPjList: any[]
        ylCfIdList: any[]
        psDataList: any[]
        tags: any[]
        wuliaoname: any[]
        isEdit: boolean
        btnList1: any[]
        btnList2: any[]
        isEdit1: boolean
        isEdit2: boolean
        isInfo1: boolean
        isInfo2: boolean
        yarnUnitsList: any[]
        wayList: any[]
      }>({
        isEdit: false,
        btnList1: [],
        btnList2: [],
        isEdit1: false,
        isEdit2: false,
        isInfo1: false,
        isInfo2: false,
        gcList: [],
        showAdd2: false,
        pageLoading: false,
        sideTitle: '新增坯布',
        dropDownData: '',
        dropDownData1: '',
        dropDownData2: '',
        dropDownData3: '',
        dropDownData4: '',
        codeList: [],
        nameList: [],
        nameList1: [],
        ggList: [],
        flList: [],
        needleCountList: [],
        machineTypeList: [],
        colorAttributeList: [],
        unitList: [],
        spRowList: [],
        rHeight: 0,
        zuzhiList: [],
        ylRowList: [],
        materialsName: '',
        rawmaterialCode: '',
        yarnCount: '',
        materialsNameList: [],
        rawmaterialCodeList: [],
        yarnCountList: [],
        zhong: '',
        yin: '',
        isDetails: false,
        cfPjList: [],
        ylCfIdList: [],
        psDataList: [],
        tags: [
          { id: '1', val: '̶' },
          { id: '2', val: 'Ո' },
          { id: '3', val: 'Ս' },
          { id: '4', val: 'Ʌ' },
          {
            id: '5',
            val: 'V',
          },
        ],
        wuliaoname: [] as any,
        yarnUnitsList: [],
        wayList: [],
      })
      const settingLoopVisible: any = ref(false)
      const setLoop = () => {
        TempSettingLoopData.value = []
        TempSettingLoopData.value = _.cloneDeep(settingLoopData.value)
        settingLoopVisible.value = true
      }
      const addFlag: any = ref(0) //-1：全部禁用 0 为未选择  1 为设置路数 2为设置循环 3为选择排三角 4为现有坯布导入排三角
      const settingLoopOK = () => {
        let isNull = TempSettingLoopData.value.some(
          (item: any) => item.wayEnd == null || item.wayEnd == null
        )
        if (isNull) {
          Message.warning('请先填写再保存！')
          return false
        }
        let wayCount = 0
        settingLoopData.value = _.cloneDeep(TempSettingLoopData.value)
        sjdata.sj.forEach((o: any) => {
          o.typeData.forEach((o1: any, id: number) => {
            // o1.needleList = []
            // xhCol.value = [{
            //   val: 0
            // }]
            const newNeedleList: any = []
            const newxhCol: any = [
              {
                val: 0,
              },
            ]
            o1.needleList.forEach((item: any) => {
              let count = 0
              settingLoopData.value.forEach((row: any) => {
                if (row.wayStart <= item.way && row.wayEnd >= item.way) {
                } else {
                  count++
                }
              })
              if (count !== settingLoopData.value.length) {
                newNeedleList.push(item)
                newxhCol.push({ val: item.way })
              }
            })
            o1.needleList = newNeedleList
            xhCol.value = newxhCol
            let onceCount = 0
            settingLoopData.value.forEach((item: any) => {
              for (let index = item.wayStart; index < item.wayEnd + 1; index++) {
                if (!o1.needleList.some((obj: any) => obj.way == index)) {
                  o1.needleList.push({
                    way: index,
                    needle: '',
                  })
                  xhCol.value.push({ val: index })
                }
                onceCount += item.loopCount
              }
            })
            o1.needleList.sort((a: any, b: any) => a.way - b.way)
            xhCol.value.sort((a, b) => a.val - b.val)
            wayCount = onceCount
          })
        })
        addFlag.value = 2
        shikaishu.value = wayCount
        TempSettingLoopData.value = []

        setSPData()
        settingLoopVisible.value = false
        return true
      }
      const wayEndChange = () => {
        countLoopBetween()
      }
      const loopCountChange = () => {
        countLoopBetween()
      }
      const showwarning = () => {
        Modal.confirm({
          title: '系统提示',
          content: '确认清除排三角的数据?',
          draggable: true,
          onOk() {
            clearPSJTempData()
          },
        })
      }
      const alignState = ref<any>(['0'])
      const alignStateOptions = [
        { label: '双面对针', value: '0' },
        { label: '罗纹对针', value: '1' },
        { label: '左对针', value: '2' },
        { label: '右对针', value: '3' },
      ]
      const alignStateChange = (val: any) => {
        if (val.length > 1) {
          const newChecked = val[1]
          alignState.value = [newChecked]
          val.splice(0, 1)
        }
      }
      //清除排三角分页下的数据，还原为初始
      const clearPSJTempData = () => {
        TempSettingLoopData.value = []
        settingLoopData.value = []
        settingLoopKeys.value = []
        addFlag.value = 0
        numb.col = 1
        numb.row = [2, 4]
        xuanhuancihu.value = 1
        xuanzepaisanjiaolist.value = []
        sjid.value = ''
        psjpb.value = ''
        sjdata.atCode = ''
        sjdata.atName = ''
        tagValue.value = pageData.tags[0].id
        psList.value = []
        psEditList.value = []
        psjpb.value = null
        let inputCheck: any = document.getElementsByClassName('inputCheck')
        for (let i = 0; i < inputCheck.length; i++) {
          inputCheck[i].checked = false
        }
        ylTableList.value.forEach(function (o: any, index: number) {
          o['wayNum'] = 0
        })
        checkedCol = []

        //清空批量修改框的值
        for (let item in moreEdit) {
          moreEdit[item] = ''
        }
        sjdata.sj = [
          {
            type: '上盘',
            typeData: [
              {
                serialNumber: 1,
                needleName: '',
                needleList: [
                  {
                    needle: '',
                    way: 1,
                  },
                ],
              },
              {
                serialNumber: 2,
                needleName: '',
                needleList: [
                  {
                    needle: '',
                    way: 1,
                  },
                ],
              },
            ],
          },
          {
            type: '下盘',
            typeData: [
              {
                serialNumber: 1,
                needleName: '',
                needleList: [{ way: 1 }],
              },
              {
                serialNumber: 2,
                needleName: '',
                needleList: [
                  {
                    needle: '',
                    way: 1,
                  },
                ],
              },
              {
                serialNumber: 3,
                needleName: '',
                needleList: [
                  {
                    needle: '',
                    way: 1,
                  },
                ],
              },
              {
                serialNumber: 4,
                needleName: '',
                needleList: [
                  {
                    needle: '',
                    way: 1,
                  },
                ],
              },
            ],
          },
        ]
        xhCol.value = []
        // for (let i = 0; i <= numb.col; i++) {
        //     xhCol.value.push({ val: i })
        // }
        for (let i = 0; i <= numb.col; i++) {
          xhCol.value.push({ val: i })
        }
        xunhuan('循环')
      }
      //循环设置删除
      const loopDel = () => {
        TempSettingLoopData.value = TempSettingLoopData.value.filter(
          (item: any) => !settingLoopKeys.value.includes(item.serialNumber)
        )
        settingLoopKeys.value = []
        // const delKeys = settingLoopKeys.value.filter(item=>item.selected)
      }
      //循环设置新增
      const loopAdd = () => {
        if (
          TempSettingLoopData.value.length == 0 ||
          TempSettingLoopData.value.every((item: any) => item.serialNumber != 1)
        ) {
          TempSettingLoopData.value.unshift({
            serialNumber: 1,
            wayStart: 1,
            wayEnd: null,
            loopCount: null,
            loopBetween: '',
          })
          return
        }
        if (
          TempSettingLoopData.value.some(
            (item: any) => item.loopBetween === undefined || item.loopBetween === ''
          )
        ) {
          Message.warning('请先填写再添加！')
          return
        }
        let obj: any = {
          serialNumber: 1,
          wayStart: 1,
        }
        let maxSerialNumber = Math.max(
          ...TempSettingLoopData.value.map((item: any) => item.serialNumber)
        )
        if (maxSerialNumber != TempSettingLoopData.value.length) {
          // for (const index in TempSettingLoopData.value) {
          //   console.log(TempSettingLoopData.value[index].serialNumber);

          //   if (TempSettingLoopData.value[index].serialNumber + 1 !== TempSettingLoopData.value[index + 1].serialNumber) {
          //     obj.serialNumber = TempSettingLoopData.value[index].serialNumber + 1
          //     obj.wayStart = parseInt(TempSettingLoopData.value[index].loopBetween.split('~')[1]) + 1
          //     TempSettingLoopData.value.push(obj)
          //     TempSettingLoopData.value.sort((a,b)=>a.serialNumber-b.serialNumber)
          //     return
          //   }
          // }
          for (let i = 1; i <= maxSerialNumber + 1; i++) {
            if (!TempSettingLoopData.value.some((item: any) => item.serialNumber === i)) {
              obj.serialNumber = i
              obj.wayStart =
                parseInt(TempSettingLoopData.value[i - 2].loopBetween.split('~')[1]) + 1

              break
            }
          }
        } else {
          let lastObj: any = TempSettingLoopData.value.find(
            (item: any) => item.serialNumber === maxSerialNumber
          )
          obj.serialNumber = maxSerialNumber + 1
          obj.wayStart = parseInt(lastObj.loopBetween.split('~')[1]) + 1
        }

        TempSettingLoopData.value.push(obj)
        TempSettingLoopData.value.sort((a: any, b: any) => a.serialNumber - b.serialNumber)
      }
      //计算循环区间
      const countLoopBetween = () => {
        TempSettingLoopData.value.forEach((item: any, index: any) => {
          if (item.wayEnd && item.loopCount) {
            TempSettingLoopData.value[index].loopBetween =
              item.wayStart +
              '~' +
              ((item.wayEnd - item.wayStart + 1) * item.loopCount + item.wayStart - 1)
            if (TempSettingLoopData.value[index + 1]) {
              TempSettingLoopData.value[index + 1].wayStart =
                (item.wayEnd - item.wayStart + 1) * item.loopCount + item.wayStart
              if (
                TempSettingLoopData.value[index + 1].wayEnd <
                (item.wayEnd - item.wayStart + 1) * item.loopCount + item.wayStart
              ) {
                TempSettingLoopData.value[index + 1].wayEnd =
                  (item.wayEnd - item.wayStart + 1) * item.loopCount + item.wayStart + 1
              }
            }
          }
        })
      }
      const settingLoopColumns = [
        {
          title: '序号',
          key: 'serialNumber',
          dataIndex: 'serialNumber',
          width: 80,
        },
        {
          title: '路数开始',
          key: 'wayStart',
          dataIndex: 'wayStart',
          width: 100,
        },
        {
          title: '路数结束',
          key: 'wayEnd',
          dataIndex: 'wayEnd',
          width: 100,
          slotName: 'wayEnd',
        },

        {
          title: '循环次数',
          key: 'loopCount',
          dataIndex: 'loopCount',
          width: 80,
          slotName: 'loopCount',
        },
        {
          title: '循环期间',
          key: 'loopBetween',
          dataIndex: 'loopBetween',
          width: 120,
        },
      ]
      const settingLoopKeys: any = ref([])
      const settingLoopCheckBox: any = reactive({
        type: 'checkbox',
        showCheckedAll: true,
        onlyCurrent: true,
      })
      const getLoopWayNum = () => {
        pageData.wayList = []

        let table = psList.value
        let settingLoopCountArr: any = []
        const rangeArr: any = []
        settingLoopData.value.forEach((item: any) => {
          rangeArr.push(item.wayEnd - item.wayStart + 1)
          for (let index = item.wayStart; index < item.wayEnd + 1; index++) {
            settingLoopCountArr.push(item.loopCount)
          }
        })

        for (var i = 1; i < table.length; i++) {
          let row = table[i]
          //上纱路数
          let numberTimes = 0
          for (let j = 3; j < row.length; j++) {
            let cellVal = row[j].val == '' ? 0 : 1
            numberTimes += settingLoopCountArr[j - 3] * cellVal
            console.log(j, cellVal, settingLoopCountArr[j - 3])
          }
          ylTableList.value[i - 1].wayNum = numberTimes
        }
        getTheoreticalYield('')
      }
      const settingLoopData: any = ref([])
      const TempSettingLoopData: any = ref([])
      const shenhebiaoji = ref(1)
      const permissionStore = usePermission()
      if (shenhebiaoji.value == 1) {
        if (permissionStore.hasPermisson('pblb.dclxg')) {
          pageData.isEdit1 = true
        }
        if (permissionStore.hasPermisson('pblb.dclxq')) {
          pageData.isInfo1 = true
        }
      } else {
        if (permissionStore.hasPermisson('pblb.yclxq')) {
          pageData.isInfo1 = true
        }
      }
      const table1Ref = ref<any>(null)
      const tableColumns = [
        {
          field: '',
          headerCheckboxSelection: true,
          checkboxSelection: true,
          width: 60,
          showDisabledCheckboxes: false,
          pinned: 'left',
        },
        {
          headerName: '坯布编号',
          field: 'greyCode',
          width: 150,
        },
        {
          headerName: '坯布名称',
          field: 'grayFabricName',
          width: 150,
        },
        {
          headerName: '是否本集团',
          field: 'processType',
          width: 150,
          cellRenderer: {
            template: `
            <a-button v-if="states == 0" status="success">本集团</a-button>
            <a-button v-else >外加工</a-button>
            `,
            setup(props: any) {
              return {
                states: props.params.data.processType,
              }
            },
          },
          filterParams: {
            valueFormatter: function (params: any) {
              return params.value == '0' ? '本集团' : params.value == '1' ? '外加工' : ''
            },
          },
        },
        {
          headerName: '纱线类别',
          field: 'yarnCountCategory',
          width: 150,
        },
        {
          headerName: '加工单价',
          field: 'machineUnit',
          width: 150,
        },
        {
          headerName: '织机转速',
          field: 'loomRevolution',
          width: 150,
        },
        {
          headerName: '机型',
          field: 'machineType',
          width: 150,
        },

        {
          headerName: '理论产量',
          field: 'theoreticalYield',
          width: 150,
        },
        {
          headerName: '针数',
          field: 'needleCount',
          width: 150,
        },
        {
          headerName: '寸数',
          field: 'dimensionFigure',
          width: 150,
        },
        {
          headerName: '总针数',
          field: 'sumNeedleCount',
          width: 150,
        },
        {
          headerName: '颜色属性',
          field: 'colorAttribute',
          width: 150,
        },

        {
          headerName: '面料种类',
          field: 'fabricType',
          width: 150,
        },
        {
          headerName: '布类',
          field: 'mercery',
          width: 150,
        },
        {
          headerName: '坯布组织',
          field: 'organization',
          width: 150,
        },
        {
          headerName: '坯布功能',
          field: 'feature',
          width: 150,
        },
        {
          headerName: '胶管名称',
          field: 'sebificDuctName',
          width: 150,
        },
        {
          headerName: '织造备注',
          field: 'weavingNote',
          width: 150,
        },
        {
          headerName: '创建时间',
          field: 'createTime',
          width: 150,
        },
        {
          headerName: '编辑',
          field: 'edit',
          slotName: 'edit',
          width: 150,
          pinned: 'right',
          cellRenderer: buttionRender,
          cellRendererParams: {
            buttonList: [
              {
                type: 'primary',
                text: '修改',
                show: pageData.isEdit1,
                typeName: 'el-button',
                Callback: (data: any) => {
                  editHandler(data, 1)
                },
              },
              {
                type: 'primary',
                text: '详情',
                show: pageData.isInfo1,
                typeName: 'el-button',
                Callback: (data: any) => {
                  editHandler(data, 2)
                },
              },
            ],
            eltagSize: 0,
          },
        },
      ]
      let configTable1 = {
        url: 'product/pdGreyInformation/selectpdGreyInformationPage', //接口路径
        queryData: {
          deleteState: 0,
          greyCode: pageData.dropDownData,
          grayFabricName: pageData.dropDownData2,
          productKind: pageData.dropDownData4,
          auditState: 0,
        },
        paginationShow: true, //分页是否显示
        invokeiIterface: true, //是否调用接
        rowMultiSelectWithClick: true, //点击行是否多选
        column: tableColumns,
        fileName: 'EmbroideryList-1',
      }
      let allDataList: any[] = []
      const getTable1Data = (data: any) => {
        allDataList = data
      }
      const table2Ref = ref<any>(null)
      const tableColumns2 = [
        {
          field: '',
          headerCheckboxSelection: true,
          checkboxSelection: true,
          width: 50,
          showDisabledCheckboxes: false,
          pinned: 'left',
        },
        {
          headerName: '坯布编号',
          field: 'greyCode',
          width: 150,
        },
        {
          headerName: '坯布名称',
          field: 'grayFabricName',
          width: 150,
        },
        {
          headerName: '是否本集团',
          field: 'processType',
          width: 150,
          cellRenderer: {
            template: `
            <a-button v-if="states == 0" status="success">本集团</a-button>
            <a-button v-else >外加工</a-button>
            `,
            setup(props: any) {
              return {
                states: props.params.data.processType,
              }
            },
          },
          filterParams: {
            valueFormatter: function (params: any) {
              return params.value == '0' ? '本集团' : params.value == '1' ? '外加工' : ''
            },
          },
        },
        {
          headerName: '纱线类别',
          field: 'yarnCountCategory',
          width: 150,
        },
        {
          headerName: '加工单价',
          field: 'machineUnit',
          width: 150,
        },
        {
          headerName: '织机转速',
          field: 'loomRevolution',
          width: 150,
        },
        {
          headerName: '机型',
          field: 'machineType',
          width: 150,
        },

        {
          headerName: '理论产量',
          field: 'theoreticalYield',
          width: 150,
        },
        {
          headerName: '针数',
          field: 'needleCount',
          width: 150,
        },
        {
          headerName: '寸数',
          field: 'dimensionFigure',
          width: 150,
        },
        {
          headerName: '总针数',
          field: 'sumNeedleCount',
          width: 150,
        },
        {
          headerName: '颜色属性',
          field: 'colorAttribute',
          width: 150,
        },

        {
          headerName: '面料种类',
          field: 'fabricType',
          width: 150,
        },
        {
          headerName: '布类',
          field: 'mercery',
          width: 150,
        },
        {
          headerName: '坯布组织',
          field: 'organization',
          width: 150,
        },
        {
          headerName: '坯布功能',
          field: 'feature',
          width: 150,
        },
        {
          headerName: '胶管名称',
          field: 'sebificDuctName',
          width: 150,
        },
        {
          headerName: '织造备注',
          field: 'weavingNote',
          width: 150,
        },
        {
          headerName: '创建时间',
          field: 'createTime',
          width: 150,
        },
        {
          headerName: '审核时间',
          field: 'auditTime',
          width: 150,
        },
        {
          headerName: '编辑',
          field: 'edit',
          slotName: 'edit',
          width: 150,
          pinned: 'right',
          cellRenderer: buttionRender,
          cellRendererParams: {
            buttonList: [
              {
                type: 'primary',
                text: '详情',
                show: pageData.isInfo1,
                typeName: 'el-button',
                Callback: (data: any) => {
                  editHandler(data, 2)
                },
              },
            ],
            eltagSize: 0,
          },
        },
      ]
      let configTable2 = {
        url: 'product/pdGreyInformation/selectpdGreyInformationPage', //接口路径
        queryData: {
          deleteState: 0,
          greyCode: pageData.dropDownData,
          grayFabricName: pageData.dropDownData2,
          productKind: pageData.dropDownData4,
          auditState: 1,
        },
        paginationShow: true, //分页是否显示
        invokeiIterface: true, //是否调用接
        rowMultiSelectWithClick: true, //点击行是否多选
        column: tableColumns2,
        fileName: 'EmbroideryList-1-2',
      }
      const getTable2Data = (data: any) => {
        allDataList = data
      }
      const total = ref(0)
      const page = ref(1)
      const size = ref(10)

      function PageSize(val: any) {
        page.value = val
        doRefresh()
      }

      function change1(val: any) {
        size.value = val
        doRefresh()
      }

      const headerShow = ref<boolean>(true)
      const ylList = ref<any[]>()
      // 成分原料
      let ylId = ref<any>()
      const ylTableList = ref<any[]>([])
      const szFinalList = [
        'A',
        'B',
        'C',
        'D',
        'E',
        'F',
        'G',
        'H',
        'I',
        'J',
        'K',
        'L',
        'M',
        'N',
        'O',
        'P',
        'Q',
        'R',
        'S',
        'T',
        'U',
        'V',
        'W',
        'X',
        'Y',
        'Z',
      ]
      const addYl = () => {
        if (selectedRowKeysAddYl.value.length == 0) {
          Message.warning('请选择原料信息！')
          return
        }
        visible1.value = false
        ylList.value = pageData.ylRowList.filter(function (o: any) {
          return selectedRowKeysAddYl.value.includes(o['id'])
        })
        for (let index = 0; index < ylList.value.length; index++) {
          pageData.ylCfIdList.push(ylList.value[index]['id'])
        }
        for (let j = 0; j < selectedRowKeysAddYl.value.length; j++) {
          const yl = ylList.value?.filter((o) => {
            return o.id === selectedRowKeysAddYl.value[j]
          })
          // // 判断原料是否被选择过
          // const temp = ylTableList.value.filter((o) => {
          //   return o.staple === yl[0].staple
          // })
          // if (temp.length > 0) {
          //   Message.warning('原料名称:' + yl[0].staple + '已有选择！')
          //   return
          // }
        }
        for (let j = 0; j < selectedRowKeysAddYl.value.length; j++) {
          const yl = ylList.value?.filter((o) => {
            return o.id === selectedRowKeysAddYl.value[j]
          })
          // 定义数组 装纱支代码
          const szList: any = []
          // 判断原料是否被选择过
          const temp = ylTableList.value.filter((o) => {
            szList.push(o['yarnSource'])
            return o.staple === yl[0].staple
          })
          var yarnSource = ''

          // 原料类别为氨纶的，固定为L
          if (yl != undefined) {
            if (yl.length > 0) {
              if (yl[0].yarnKind == '氨纶') {
                yarnSource = 'L'
              } else {
                // 由A到Z自增赋值纱支代码
                for (var i = 0; i < szFinalList.length; i++) {
                  let tempSourse = szFinalList[i]
                  if (!szList.includes(tempSourse)) {
                    yarnSource = tempSourse
                    break
                  }
                }
              }
              yl[0]['yarnSource'] = yarnSource
              yl[0]['ylId'] = yl[0]['id']
              yl[0]['id'] = undefined
              ylTableList.value.push(yl[0])
            }
          }
          getWayNum()
        }

        pageData.ylRowList = []
        selectedRowKeysAddYl.value = []
        ylData.value = {
          materialsName: '',
          rawmaterialCode: '',
          yarnCount: '',
          auditState: 1,
          processType: 0,
        }
        dataForm.grayFabricName = ''
        getGrayFabricName()
        ylTableList.value.forEach(function (o: any) {
          o['weavingDamage'] = Number(o['property'])
          //排纱 数据
          RendPs(1)
          //悬浮提示
          // huoquyuanliaomingcheng(o);
        })
      }

      //判断用户勾选了多少条原料信息然后拼接成分和英文成分
      function zhongAndYin(scSb: any, record: any) {
        //基础信息 的中文成分和英文成分  中（中文成分加纱支比）英（英文成分加纱支比）
        // 取成分
        pageData.zhong = ''
        pageData.yin = ''

        if (pageData.ylCfIdList.length > 0) {
          post({
            url: 'product/RawmaterialComponent/getList',
            data: { infoId: '' },
          }).then(({ code, data }: any) => {
            if (code === 200) {
              pageData.cfPjList = data.filter(function (o: any) {
                return pageData.ylCfIdList.includes(o['infoId'])
              })

              let list: any = []
              let ob = {}
              pageData.cfPjList.forEach(function (o: any) {
                if (ob[o['infoId']] == undefined) {
                  ob[o['infoId']] = {}
                  ob[o['infoId']]['ingredient'] = o['ingredient']
                  ob[o['infoId']]['ingredientEnglish'] = o['ingredientEnglish']
                } else {
                  ob[o['infoId']]['ingredient'] =
                    ob[o['infoId']]['ingredient'] + '/' + o['ingredient']
                  ob[o['infoId']]['ingredientEnglish'] =
                    ob[o['infoId']]['ingredientEnglish'] + '/' + o['ingredientEnglish']
                }
              })

              for (let key in ob) {
                ob[key]['ylId'] = key
                list.push(ob[key])
              }
              list.forEach(function (o: any) {
                ylTableList.value.forEach(function (o1: any) {
                  if (o1['ylId'] == o['ylId']) {
                    if (
                      o['ingredient'] != undefined &&
                      o['ingredient'] != '' &&
                      o1['actualYarn'] != undefined &&
                      o1['actualYarn'] != ''
                    ) {
                      if (pageData.zhong == '') {
                        pageData.zhong = o1['actualYarn'] + '%' + o['ingredient']
                      } else {
                        pageData.zhong += '+' + o1['actualYarn'] + '%' + o['ingredient']
                      }
                    } else {
                      pageData.zhong += ''
                    }
                    if (
                      o['ingredientEnglish'] != undefined &&
                      o['ingredientEnglish'] != '' &&
                      o1['actualYarn'] != undefined &&
                      o1['actualYarn'] != ''
                    ) {
                      if (pageData.yin == '') {
                        pageData.yin = o1['actualYarn'] + '%' + o['ingredientEnglish']
                      } else {
                        pageData.yin += '+' + o1['actualYarn'] + '%' + o['ingredientEnglish']
                      }
                    } else {
                      pageData.yin += ''
                    }
                  }
                })
              })
              dataForm.ingredient = pageData.zhong
              dataForm.englishIngredient = pageData.yin
            }
          })
        }
      }

      // 构造坯布名称
      function getGrayFabricName() {
        dataForm.grayFabricName = ''
        if (dataForm.mercery != '' && ylTableList.value.length > 0) {
          ylTableList.value.forEach(function (o) {
            if (dataForm.grayFabricName == '') {
              dataForm.grayFabricName += o.staple
            } else {
              dataForm.grayFabricName += '+' + o.staple
            }
          })
          dataForm.grayFabricName += '+' + (dataForm.mercery == null ? '' : dataForm.mercery)
        }
      }

      //渲染排纱方法
      function RendPs(num: any) {
        // debugger;
        if (num != 1) {
          psList.value = []
        }
        if (psList.value.length == 0) {
          let list: any = []

          for (let j = 0; j < numb.col + 3; j++) {
            list[j] = { val: '' }
            if (j == 2) {
              list[j] = { val: '排纱' }
            }
          }
          psList.value.push(list)
          for (let index = 0; index < ylTableList.value.length; index++) {
            let lis: any = []
            for (let j = 0; j < numb.col + 3; j++) {
              lis[j] = { val: '' }
              if (j == 0) {
                lis[j] = { val: '纱长(cm)' }
              }
              if (j == 1) {
                lis[j] = { val: ylTableList.value[index]['yarnSource'] }
              }
            }
            psList.value.push(lis)
          }
        } else {
          var list: any = []
          for (let j = 0; j < numb.col + 3; j++) {
            list[j] = { val: '' }
            if (j == 0) {
              list[j] = { val: '纱长(cm)' }
            }
            if (j == 1) {
              list[j] = { val: ylTableList.value[psList.value.length - 1]['yarnSource'] }
            }
          }
          psList.value.push(list)
        }
      }

      const changeYarnSource = (record: any) => {
        if (record.yarnKind == '氨纶') {
          Message.warning('原料类别为:' + record.yarnKind + ',不可修改纱支代码！')
          record.yarnSource = 'L'
          return
        }
        let temp = ylTableList.value.filter((o) => {
          return o.yarnSource === record.yarnSource && o.staple != record.staple
        })
        if (temp.length > 0) {
          Message.warning('纱支代码:' + record.yarnSource + '已被使用！')
          record.yarnSource = ''
          return
        }
      }
      const delYl = () => {
        let keys = selectedRowKeys.value
        ylTableList.value = ylTableList.value.filter((o) => {
          return !keys.includes(o.yarnSource)
        })
        //找到此排纱对应的删除掉的原料信息
        psList.value = psList.value.filter(function (o: any) {
          return !keys.includes(o[1]['val'])
        })

        selectedRowKeys.value = []
        getGrayFabricName()
      }

      // 成分 组织排针
      const zzpzListSelect = ref<any>([])
      const zzpzid = ref()
      const zzpzdata = ref<any[]>([
        {
          upBasin: '',
          belowBasin: '',
          id: '',
          pdOrganizationPinId: '',
        },
      ])
      const colNumber = ref<number>(1)
      const alignType = ref<any>('0')
      // 设置组织排针列数确认
      const addZhen = () => {
        alignType.value = alignState.value[0]
        let n = colNumber.value - zzpzdata.value.length
        if (n < 0) {
          for (let i = n; i < 0; i++) {
            zzpzdata.value.pop()
          }
        } else if (n > 0) {
          for (let i = 0; i < n; i++) {
            zzpzdata.value.push({
              upBasin: '',
              belowBasin: '',
              id: '',
              pdOrganizationPinId: '',
            })
          }
        } else {
          return
        }
      }
      const zzpzid2 = ref()
      const minsZhen = () => {
        if (zzpzdata.value.length == 1) {
          Message.warning('最少保留一列排针！')
          return
        }
        zzpzdata.value.length = zzpzdata.value.length - 1
      }

      const zzpzok = () => {
        //sessionStorage.setItem("组织排针",JSON.stringify(zzpzid.value))
        if (zzpzid.value == undefined || zzpzid.value == '') {
          Message.warning('请选择组织排针！')
          zzpzdata.value = [
            {
              upBasin: '',
              belowBasin: '',
              id: '',
              pdOrganizationPinId: '',
            },
          ]
          colNumber.value = 1
          zzpzid2.value = 1
          return
        }
        post({
          url: '/product/organizationPin/select',
          data: {
            id: zzpzid.value,
          },
        }).then(({ code, data }) => {
          if (code === 200) {
            data.map((o: any) => {
              // o.belowBasin = ''
              o.id = undefined
            })
            console.log(data)
            zzpzdata.value = data
            colNumber.value = data.length
            zzpzid2.value = zzpzid.value
          }
        })
      }
      // 初始化成分-组织排针下拉框
      const zzpzfocus = () => {
        zzpzSelect('')
      }
      const zzpzSelect = (val: any) => {
        post({
          url: 'product/organizationPin/greyExtendValue',
          data: {
            organizationName: val,
            deleteState: 0,
          },
        }).then((res) => {
          if (res.code === 200) {
            zzpzListSelect.value = res.data
          }
        })
      }

      const zzpzSelectType = (val: any) => {
        post({
          url: 'product/organizationPin/getListValue',
          data: {
            machineType: dataForm.machineType,
            deleteState: 0,
            organizationName: val,
          },
        }).then((res) => {
          if (res.code === 200) {
            zzpzListSelect.value = res.data
          }
        })
      }
      // 初始化成分-裁口排针下拉框
      const ckpzfocus = () => {
        ckpzSelect('')
      }
      //  裁口排针
      const ckpzSelectList = ref<any[]>([])
      const ckpzSelect = (val: any) => {
        post({
          url: 'product/pdCuttingMouthNeedle/getList',
          data: {
            cmdName: val,
            deleteState: 0,
          },
        }).then(({ code, data }) => {
          if (code === 200) {
            ckpzSelectList.value = data
          }
        })
      }
      const ckpzid = ref()
      const ckpzobj = reactive<any>({
        id: 0,
        pinHeader: '',
        arrangement: '',
        cmdName: '',
      })
      const ckpzadd = () => {
        if (ckpzid.value == undefined || ckpzid.value == '') {
          Message.warning('请选择裁口排针！')
          ckpzobj.id = 0
          ckpzobj.pinHeader = ''
          ckpzobj.arrangement = ''
          ckpzobj.cmdName = ''
          return
        }
        const obj: any = ckpzSelectList.value.filter((o: any) => o.id === ckpzid.value)[0]
        ckpzobj.id = obj.id
        ckpzobj.pinHeader = obj.pinHeader
        ckpzobj.arrangement = obj.arrangement
        ckpzobj.cmdName = obj.cmdName
        // ckpzid.value = ''
      }
      const copyckpz = () => {
        post({
          url: 'product/pdCuttingMouthNeedle/copyCuttingMouthNeedle',
          data: {
            id: ckpzobj.id,
          },
        }).then(({ code, data }) => {
          if (code === 200) {
            ckpzobj.id = data.id
            ckpzobj.arrangement = data.arrangement
            ckpzobj.pinHeader = data.pinHeader
          }
        })
      }

      const sjdata = reactive<{
        sjid: string | number
        sj: any[]
        atCode: string
        atName: string
        remark: string
      }>({
        sjid: '',
        sj: [],
        atCode: '',
        atName: '',
        remark: '',
      })
      const sjname = ref('')
      const sjSelectList = ref<any[]>([])

      const sjOk = () => {
        paishabiaoji.value = 0
        post({
          url: 'product/arrangementTriangleInfo/getInfoByAtId?id=' + sjid.value,
          data: {
            atName: sjname,
          },
        }).then(({ code, data }) => {
          if (code === 200) {
            huancunpanduanziduan.value = ''
            let info = data.info
            xuanzepaisanjiaolist.value = data.info
            if (info.length > 0) {
              if (info[0].typeData.length > 0) {
                // numb.col = (info[0].typeData[0].needleList).length;

                xuanhuancihu.value = 1
                numb.col = info[0].typeData[0].needleList.length
                info.map((o: any, index: any) => {
                  numb.row[index] = o.typeData.length
                })
                //  numb.row[0]=info[0].typeData.length
                //    numb.row[1]=info[1].typeData.length
                shikaishu.value = numb.col
              } else {
              }
            } else {
            }
            xhCol.value = [
              {
                val: 0,
              },
            ]
            // for (let i = 0; i <= numb.col; i++) {
            //   xhCol.value.push({ val: i })
            // }
            let onceCount = 0
            settingLoopData.value = data.loopList
            data.loopList.forEach((item: any) => {
              for (let index = item.wayStart; index < item.wayEnd + 1; index++) {
                xhCol.value.push({ val: index })

                onceCount += item.loopCount
              }
            })
            shikaishu.value = onceCount
            //排纱 数据
            RendPs(2)
            //sjid.value = ''
            sjdata.sjid = data.id
            sjdata.sj = data.info
            if (sjdata.sj.length === 1) {
              dataForm.models = '1'
            } else {
              dataForm.models = '2'
            }
            ;(sjdata.atCode = data.atCode), (sjdata.atName = data.atName)
            sjdata.remark = data.remark
            if (data.loopList?.length > 0) {
              settingLoopData.value = data.loopList
            } else {
              settingLoopData.value = []
            }
            addFlag.value = 3
          }
        })
      }
      const sjid = ref()
      const focusSj = () => {
        post({
          url: 'product/arrangementTriangle/getList',
          data: {
            atName: '',
            obsoleteState: 0,
            deleteState: 0,
            models:
              dataForm.machineType == null
                ? undefined
                : dataForm.machineType == ''
                ? undefined
                : dataForm.machineType,
          },
        }).then(({ code, data }) => {
          if (code === 200) {
            sjSelectList.value = data
          }
        })
      }
      const sjSelect = (val: any) => {
        post({
          url: 'product/arrangementTriangle/getList',
          data: {
            atName: val,
            obsoleteState: 0,
            deleteState: 0,
          },
        }).then(({ code, data }) => {
          if (code === 200) {
            sjSelectList.value = data
          }
        })
      }

      function doRefresh() {
        // pageData.pageLoading = true
        if (shenhebiaoji.value == 1) {
          nextTick(() => {
            table1Ref.value.setQuery({
              deleteState: 0,
              greyCode: pageData.dropDownData,
              grayFabricName: pageData.dropDownData2,
              productKind: pageData.dropDownData4,
              auditState: 0,
            })
          })
        } else {
          nextTick(() => {
            table2Ref.value.setQuery({
              deleteState: 0,
              greyCode: pageData.dropDownData,
              grayFabricName: pageData.dropDownData2,
              productKind: pageData.dropDownData4,
              auditState: 1,
            })
          })
        }
      }

      const { selectedRowKeys, onSelectionChange } = useRowSelection()

      const pagination = usePagination(doRefresh)
      const table = useTable()
      const rowKey = useRowKey('id')
      const tableColumns1 = useTableColumn([
        {
          title: '用纱代码',
          key: 'yarnSource',
          dataIndex: 'yarnSource',
          width: 150,
          slotName: 'yarnSource',
        },
        {
          title: '原料编号',
          key: 'yarnCode',
          dataIndex: 'yarnCode',
          width: 150,
        },
        {
          title: '原料名称',
          key: 'staple',
          dataIndex: 'staple',
          width: 150,
        },
        {
          title: '色号',
          key: 'colourNumber',
          dataIndex: 'colourNumber',
          width: 150,
          slotName: 'colourNumber',
        },
        {
          title: '色称',
          key: 'colorAccording',
          dataIndex: 'colorAccording',
          width: 150,
          slotName: 'colorAccording',
        },
        {
          title: '等级',
          key: 'grade',
          dataIndex: 'grade',
          width: 150,
          slotName: 'grade',
        },
        {
          title: '纱线单位',
          key: 'yarnUnits',
          dataIndex: 'yarnUnits',
          width: 150,
          slotName: 'yarnUnits',
        },
        {
          title: '丹尼尔系数',
          key: 'danielCoefficient',
          dataIndex: 'danielCoefficient',
          width: 150,
        },
        {
          title: '纱支比例(%)',
          key: 'yarnCountProportion',
          dataIndex: 'yarnCountProportion',
          width: 150,
          slotName: 'yarnCountProportion',
        },
        {
          title: '实测纱比(%)',
          key: 'actualYarn',
          dataIndex: 'actualYarn',
          width: 150,
          slotName: 'actualYarn',
        },
        {
          title: '是否超出范围',
          key: 'yujing',
          dataIndex: 'yujing',
          width: 150,
          slotName: 'yujing',
        },
        {
          title: '织布损(%)',
          key: 'weavingDamage',
          dataIndex: 'weavingDamage',
          width: 150,
          slotName: 'weavingDamage',
        },
        {
          title: '颜色组号',
          key: 'colorGroup',
          dataIndex: 'colorGroup',
          width: 150,
          slotName: 'colorGroup',
        },
        {
          title: '循环间距',
          key: 'circularSpacing',
          dataIndex: 'circularSpacing',
          width: 150,
          slotName: 'circularSpacing',
        },
        {
          title: '纱长',
          key: 'yarnLong',
          dataIndex: 'yarnLong',
          width: 150,
          slotName: 'yarnLong',
        },
        {
          title: '上纱路数',
          key: 'wayNum',
          dataIndex: 'wayNum',
          width: 150,
          slotName: 'wayNum',
        },
      ])
      const dataForm = reactive<RawMaterialsList>({
        orderMachineType: '',
        exploitCode: '',
        shipperUnits: '',
        activeOutput: 0,
        clothKindOfName: '',
        loomRevolution: 0,
        yarnCountCode: '',
        sebificDuctName: '',
        id: '',
        starts: '',
        yarnCountCategory: '',
        playingCards: '',
        updateName: '',
        greyCode: '',
        inventoryLowerLimit: '',
        beadJuggle: '',
        knittingNeedleType: '',
        productKind: '',
        unit: '',
        versions: '',
        associatedGoods: '',
        dimensionFigure: 0,
        grade: '',
        createName: '',
        colorAccording: '',
        needleType: '',
        englishName: '',
        weaverPrice: 0,
        machineUnit: 0,
        weavingDamage: 0,
        actualYarn: 0,
        yarnCountIngredient: '',
        remark: '',
        productTime: '',
        measuredYarnCount: '',
        fabricType: '',
        alwaysGoes: 0,
        needleCount: 0,
        feature: '',
        mercery: '',
        sumNeedleCount: null,
        colorGroup: '',
        machineType: '',
        deleteState: 0,
        outsideProcessingClient: '',
        ingredient: '',
        englishIngredient: '',
        weavingNote: '',
        chineseIngredient: '',
        yarnSource: '',
        staple: '',
        yarnKind: '',
        stockNature: '',
        sYarnProperty: '',
        danielCoefficient: '',
        yarnCountProportion: 0,
        inventoryDivisionMachine: '',
        colorAttribute: '',
        theoryCapacity: 0,
        updateTime: '',
        grayFabricName: '',
        drawnNeedleState: null,
        scutchingState: '',
        putOnRecordsCode: '',
        yarnCountName: '',
        createTime: '',
        organization: '',
        commodityState: '',
        category: '',
        inventoryUpperLimit: '',
        circulationGap: '',
        popularizeCommodity: '',
        finishedLimit: '',
        finishedWeight: '',
        colourNumber: 0,
        models: '2',
        processType: 0,
        rubberTube: '',
        checkUnits: '',
        perchPrice: 0,
        perchUnits: '',
        yarnLength: '',
        theoreticalYield: 0,
        differentiateState: 4,
      })

      //下拉框得到焦点
      const focusSel = () => {
        selCxAll({ greyCode: '' })
      }
      //下拉框得到焦点
      const focusSel1 = () => {
        selCxAll1({ materialsName: '', auditState: 1 })
      }
      //下拉框得到焦点
      const focusSel2 = () => {
        selCxAll2({ grayFabricName: '' })
      }
      //下拉框得到焦点
      const focusSel3 = () => {
        selCxAll3({ model: '' })
      }
      let typeNum: any = null
      //下拉框得到焦点
      const focusSel4 = (num: any) => {
        typeNum = num
        if (num == 2) {
          selCxAll4({ productTypeName: '' })
        } else {
          selCxAll4({ productKind: '' })
        }
      }
      //下拉框得到焦点
      const focusSel9 = (num: any) => {
        typeNum = num
        if (num == 2) {
          selCxAll9({ productTypeName: '' })
        }
      }
      const focusSel6 = () => {
        selCxAll6({
          categoryName: '',
        })
      }
      // 针数下拉框
      const focusNeedleCountList = () => {
        getNeedleCountList({ model: '' })
      }
      // 机型下拉框
      const focusMachineTypeList = () => {
        // getMachineTypeList({ machineName: "" })
        jitaileixing()
      }
      // 颜色属性
      const focusColorAttribute = () => {
        getColorAttributeList({ colorattribute: '' })
      }
      // 单位
      const focusunit = () => {
        getUnitList()
      }
      // 初始化成分-原料下拉框
      const focusYl = () => {
        ylSelect('')
      }

      //下拉数据  坯布编号
      const options = ref<any>(pageData.codeList)
      const loading = ref(false)
      const handleSearch = (value: any) => {
        if (value) {
          const ob = { greyCode: value }
          loading.value = true

          selCxAll(ob)
          options.value = pageData.codeList
          loading.value = false
        } else {
          options.value = []
        }
      }

      //下拉框查询 坯布编号
      function selCxAll(val: any) {
        post({
          url: 'product/Rawmaterial/getGreyDrop',
          data: val,
        }).then(({ data, code }: any) => {
          if (code === 200) {
            // (data as string[]).splice(0, 0, "全部");
            pageData.codeList = data
          } else {
            Message.error({
              content: '查询失败！',
              duration: 5000,
            })
          }
        })
      }

      //下拉数据 名称
      const options1 = ref<any>(pageData.nameList)
      const loading1 = ref(false)
      const handleSearch1 = (value: any) => {
        if (value) {
          const ob = { materialsName: value }
          loading.value = true

          selCxAll1(ob)
          options.value = pageData.nameList
          loading.value = false
        } else {
          options.value = []
        }
      }

      //下拉框查询 名称
      function selCxAll1(val: any) {
        post({
          url: 'product/Rawmaterial/getRawmaterialsNameDrop',
          data: val,
        }).then(({ data, code }: any) => {
          if (code === 200) {
            pageData.nameList = data
          } else {
            Message.error({
              content: '查询失败！',
              duration: 5000,
            })
          }
        })
      }

      //下拉数据  坯布名称
      const options2 = ref<any>(pageData.nameList1)
      const loading2 = ref(false)
      const handleSearch2 = (value: any) => {
        if (value) {
          const ob = { grayFabricName: value }
          loading.value = true

          selCxAll2(ob)
          options.value = pageData.nameList1
          loading.value = false
        } else {
          options.value = []
        }
      }

      //下拉框查询 坯布名称
      function selCxAll2(val: any) {
        post({
          url: 'product/Rawmaterial/getGreyDrop',
          data: val,
        }).then(({ data, code }: any) => {
          if (code === 200) {
            // (data as string[]).splice(0, 0, "全部");
            pageData.nameList1 = data
          } else {
            Message.error({
              content: '查询失败！',
              duration: 5000,
            })
          }
        })
      }

      //下拉数据  规格
      const options3 = ref<any>(pageData.ggList)
      const loading3 = ref(false)
      const handleSearch3 = (value: any) => {
        if (value) {
          const ob = { model: value }
          loading.value = true

          selCxAll3(ob)
          options.value = pageData.ggList
          loading.value = false
        } else {
          options.value = []
        }
      }

      //下拉框查询 规格
      function selCxAll3(val: any) {
        post({
          url: 'product/Rawmaterial/getRawmaterialsNameDrop',
          data: val,
        }).then(({ data, code }: any) => {
          if (code === 200) {
            // (data as string[]).splice(0, 0, "全部");
            pageData.ggList = data
          } else {
            Message.error({
              content: '查询失败！',
              duration: 5000,
            })
          }
        })
      }

      //通用
      const tags = [
        { id: '1', val: '̶' },
        { id: '2', val: 'Ո' },
        { id: '3', val: 'Ս' },
        { id: '4', val: 'Ʌ' },
        {
          id: '5',
          val: 'V',
        },
      ]

      // const tags2=[{ id: '1', val: '̶' }, { id: '2', val: "Ո" }, { id: '4', val: 'Ʌ' }]
      //下拉数据 分类
      const options4 = ref<any>(pageData.flList)
      const loading4 = ref(false)
      const handleSearch4 = (value: any) => {
        if (value) {
          let ob = {}
          if (typeNum == 2) {
            ob = { productTypeName: value }
          } else {
            ob = { productKind: value }
          }
          loading.value = true
          selCxAll4(ob)
          options.value = pageData.flList
          loading.value = false
        } else {
          options.value = []
        }
      }

      //下拉框查询 分类
      function selCxAll4(val: any) {
        if (typeNum == 2) {
          post({
            url: 'product/Rawmaterial/getProductTypeDrop',
            data: val,
          }).then(({ data, code }: any) => {
            if (code === 200) {
              // (data as string[]).splice(0, 0, "全部");
              pageData.flList = data
            } else {
              Message.error({
                content: '查询失败！',
                duration: 5000,
              })
            }
          })
        } else {
          post({
            url: 'product/pdGreyInformation/getFieldValue',
            data: val,
          }).then(({ data, code }: any) => {
            if (code === 200) {
              // (data as string[]).splice(0, 0, "全部");
              pageData.flList = data
            } else {
              Message.error({
                content: '查询失败！',
                duration: 5000,
              })
            }
          })
        }
      }

      //下拉框查询 分类
      function selCxAll9(val: any) {
        if (typeNum == 2) {
          post({
            url: 'product/rubberhoseSet/getList',
            data: val,
          }).then(({ data, code }: any) => {
            if (code === 200) {
              // (data as string[]).splice(0, 0, "全部");
              pageData.flList = data
            } else {
              Message.error({
                content: '查询失败！',
                duration: 5000,
              })
            }
          })
        }
      }

      //下拉数据 组织
      const options6 = ref<any>(pageData.zuzhiList)
      const loading6 = ref(false)
      const handleSearch6 = (value: any) => {
        if (value) {
          const ob = { categoryName: value }
          loading6.value = true
          selCxAll6(ob)
          options6.value = pageData.zuzhiList
          loading6.value = false
        } else {
          options6.value = []
        }
      }

      //下拉框查询 组织
      function selCxAll6(val: any) {
        post({
          url: 'product/pdGreyInformationOrganization/getFieldValue',
          data: val,
        }).then(({ data, code }: any) => {
          if (code === 200) {
            pageData.zuzhiList = data
          } else {
            Message.error({
              content: '查询失败！',
              duration: 5000,
            })
          }
        })
      }

      // 针数下拉框
      const searchNeedleCountList = (value: any) => {
        // if (value) {
        const ob = { model: value }
        loading.value = true
        getNeedleCountList(ob)
        options.value = pageData.needleCountList
        loading.value = false
        // } else {
        //   options.value = []
        // }
      }
      const getNeedleCountList = (val: any) => {
        post({
          url: 'product/workdrumEquipment/getnumber',
          data: val,
        }).then(({ data, code }: any) => {
          if (code === 200) {
            // (data as string[]).splice(0, 0, "全部");
            pageData.needleCountList = data
          } else {
            Message.error({
              content: '查询失败！',
              duration: 5000,
            })
          }
        })
      }
      // 机型下拉框
      const searchMachineTypeList = (value: any) => {
        if (value) {
          const ob = { machineName: value }
          loading.value = true
          getMachineTypeList(ob)
          options.value = pageData.machineTypeList
          loading.value = false
        } else {
          options.value = []
        }
      }
      // 机型下拉框
      const getMachineTypeList = (val: any) => {
        post({
          url: 'product/GreyMachinetype/getFieldValue',
          data: val,
        }).then(({ code, data }: any) => {
          if (code === 200) {
            pageData.machineTypeList = data
          } else {
            Message.error({
              content: '查询失败',
              duration: 5000,
            })
          }
        })
      }
      // 颜色属性下拉框
      const searchColorAttribute = (value: any) => {
        if (value) {
          const ob = { colorattribute: value }
          loading.value = true
          getColorAttributeList(ob)
          options.value = pageData.colorAttributeList
          loading.value = false
        } else {
          options.value = []
        }
      }
      // 颜色属性下拉框
      const getColorAttributeList = (val: any) => {
        post({
          url: 'product/greyColorattribute/getFieldValue',
          data: val,
        }).then(({ code, data }: any) => {
          if (code === 200) {
            pageData.colorAttributeList = data
          } else {
            Message.error({
              content: '查询失败',
              duration: 5000,
            })
          }
        })
      }
      // 单位下拉框
      const searchUnit = (value: any) => {
        if (value) {
          const ob = {
            field: 'unit',
            value: value,
          }
          loading.value = true
          getUnitList()
          options.value = pageData.unitList
          loading.value = false
        } else {
          options.value = []
        }
      }
      // 单位下拉框
      const getUnitList = () => {
        post({
          url: 'dict/dictTypeDetail/getListByCodeType?codeType=17',
        }).then(({ code, data }: any) => {
          if (code == 200) {
            pageData.unitList = data
          } else {
            Message.error({
              content: '查询失败',
              duration: 5000,
            })
          }
        })
      }

      const ylSelect = (val: any) => {
        post({
          url: 'product/Rawmaterial/getInfo',
          data: {
            materialsName: val,
          },
        }).then((res) => {
          if (res.code === 200) {
            ylList.value = res.data
          }
        })
      }
      onMounted(() => {
        doRefresh()
        // 切换tap到本页面执行的方法
        emitter.on('EmbroideryList', () => {
          selCxAll({})
          doRefresh()

          //根据账号类型判断是否本集团
        })
        // getwuliao({ materialName: '',auditState:1})
        pageData.rHeight = document.getElementsByClassName('arco-tabs-content')[0]?.clientHeight
        //弹出层的高
        if (pageData.rHeight !== undefined) {
          pageData.rHeight = pageData.rHeight - 100
        }
        window.addEventListener('resize', () => {
          pageData.rHeight = document.getElementsByClassName('arco-tabs-content')[0]?.clientHeight
          //弹出层的高
          if (pageData.rHeight !== undefined) {
            pageData.rHeight = pageData.rHeight - 100
          }
        })
      })
      //查询
      const selectHandler = () => {
        page.value = 1
        doRefresh()
      }
      const queryData = reactive({
        firm: '',
      })
      const addHandler = () => {
        shabili()
        // shifoubenjituan();
        addFlag.value = 0
        xuanzepaisanjiaolist.value = []
        crossMemo.value = ''
        machineUnit.value = 0
        shikaishu.value = 1
        xuanhuancihu.value = 1
        theoryPrice.value = 0
        psList.value = []
        shifoubenjituan()
        machineUnit.value = 0
        pageData.ylCfIdList = []
        selectedRowKeys.value = []
        pageData.isDetails = false
        pageData.zhong = ''
        pageData.yin = ''
        sjdata.atCode = ''
        sjdata.atName = ''
        sjdata.remark = ''
        sjdata.sjid = ''
        sjid.value = ''
        sjdata.sj = []
        zzpzdata.value = []
        zzpzid.value = ''
        zzpzid2.value = []
        ckpzid.value = ''
        ckpzobj.arrangement = ''
        ckpzobj.pinHeader = ''
        ckpzobj.id = 0
        ckpzobj.id = 0
        ylId.value = ''
        colNumber.value = 0
        ylTableList.value.length = 0
        psjpb.value = null
        pageData.spRowList = []
        settingLoopData.value = []
        Object.keys(dataForm).forEach((o) => {
          if (
            o == 'activeOutput' ||
            o == 'loomRevolution' ||
            o == 'weaverPrice' ||
            o == 'alwaysGoes' ||
            o == 'deleteState' ||
            o == 'theoryCapacity' ||
            o == 'processType' ||
            o == 'machineUnit' ||
            o == 'perchPrice' ||
            o == 'theoreticalYield'
          ) {
            dataForm[o] = 0
          }
          // else if (o == 'scutchingState') {
          //   dataForm[o] = 2
          // }
          else {
            dataForm[o] = ''
          }
          // if (o == 'drawnNeedleState') {
          //   dataForm[o] = 2
          // }
        })
        pageData.showAdd2 = true
        pageData.sideTitle = '新增坯布'
        numb.col = 1
        numb.row = [2, 4]

        sjdata.sj = [
          {
            type: '上盘',
            typeData: [
              {
                serialNumber: 1,
                needleName: '',
                needleList: [
                  {
                    needle: '',
                    way: 1,
                  },
                ],
              },
              {
                serialNumber: 2,
                needleName: '',
                needleList: [
                  {
                    needle: '',
                    way: 1,
                  },
                ],
              },
            ],
          },
          {
            type: '下盘',
            typeData: [
              {
                serialNumber: 1,
                needleName: '',
                needleList: [{ way: 1 }],
              },
              {
                serialNumber: 2,
                needleName: '',
                needleList: [
                  {
                    needle: '',
                    way: 1,
                  },
                ],
              },
              {
                serialNumber: 3,
                needleName: '',
                needleList: [
                  {
                    needle: '',
                    way: 1,
                  },
                ],
              },
              {
                serialNumber: 4,
                needleName: '',
                needleList: [
                  {
                    needle: '',
                    way: 1,
                  },
                ],
              },
            ],
          },
        ]
        xhCol.value = []
        // for (let i = 0; i <= numb.col; i++) {
        //     xhCol.value.push({ val: i })
        // }
        for (let i = 0; i <= numb.col; i++) {
          xhCol.value.push({ val: i })
        }
        dataForm.models = '2'
      }
      let xhCol = ref<any[]>([])
      const ewsj = ref<any>([])
      //修改 record（本行数据）
      const editHandler = (record: any, num: any) => {
        psjpb.value = null
        focusPs()
        //唐威加
        //shifoubenjituan();
        shabili()
        // psList.value = [];
        ;(paishabiaoji.value = 0), (huancunpanduanziduan.value = '')
        sjdata.sj = []

        ylTableList.value = []
        zzpzSelect('')
        id.value = record.id
        // -----------
        pageData.ylCfIdList = []
        selectedRowKeys.value = []
        if (num == 2) {
          pageData.isDetails = true
        } else {
          pageData.isDetails = false
        }
        pageData.zhong = ''
        pageData.yin = ''
        const idToData = allDataList.filter((item) => item.id == record.id)
        post({
          url: 'product/pdGreyInformation/select',
          data: {
            id: record.id,
          },
        }).then(({ code, data }) => {
          if (code === 200) {
            if (data.organizationPinSons.length) {
              alignState.value = [String(data.organizationPinSons[0].alignState)]
              alignType.value = alignState.value[0]
            }
            // 原料列表
            ylTableList.value = data.yarnStructures
            // jiShuanSha()
            ylTableList.value.forEach(function (o: any) {
              pageData.ylCfIdList.push(o['ylId'])
            })
            if (data.arrangementTriangleGreys.loopList?.length > 0) {
              settingLoopData.value = data.arrangementTriangleGreys.loopList
            } else {
              settingLoopData.value = []
            }
            addFlag.value = -1
            //tw加
            ylTableList.value.forEach((o: any) => {
              var cha = o.actualYarn - o.yarnCountProportion
              for (let item of shabilist.value) {
                if (cha >= Number(item['yarnCountMin']) && cha <= Number(item['yarnCountMax'])) {
                  o.jieguo = 1
                  break
                } else {
                  o.jieguo = 2
                }
              }
            })
            // machineUnit.value = data.greyInformation.machineUnit
            dataForm.processType = data.greyInformation.processType
            crossMemo.value = data.greyInformation.crossMemo
            dataForm.alwaysGoes = data.greyInformation.alwaysGoes
            theoryPrice.value = data.greyInformation.theoryPrice
            if (
              data.arrangementTriangleGreys['info'] != undefined &&
              data.arrangementTriangleGreys['info'] != null
            ) {
              data.arrangementTriangleGreys.info.map((o: any) => {
                o.typeData.map((a: any) => {
                  a.needleList.map((b: any, index: any) => {
                    if (index == 0) {
                      xuanhuancihu.value = b.circulationNum
                      shikaishu.value = b.realOpenNum
                    }
                  })
                })
              })
            }

            sjid.value = data.arrangementTriangleGreys.atName
            ckpzid.value = data.arrangementTriangleGreys.cmdName
            //---------------
            // 组织排针 列数
            colNumber.value =
              data.organizationPinSons.length == 0 ? 1 : data.organizationPinSons.length
            // 组织排针 数据
            zzpzdata.value =
              data.organizationPinSons.length == 0
                ? [
                    {
                      upBasin: '',
                      belowBasin: '',
                      id: '',
                      pdOrganizationPinId: '',
                    },
                  ]
                : data.organizationPinSons
            // 裁口排针
            if (data.cuttingMouthNeedleGrey != null) {
              let cuttingMouthNeedleGrey = data.cuttingMouthNeedleGrey
              ckpzobj.id = cuttingMouthNeedleGrey.id
              ckpzobj.pinHeader = cuttingMouthNeedleGrey.pinHeader
              ckpzobj.arrangement = cuttingMouthNeedleGrey.arrangement
              ckpzobj.cmdName = cuttingMouthNeedleGrey.cmdName
            }
            //tw加
            if (data.cuttingMouthNeedleGrey != null && data.cuttingMouthNeedleGrey.length > 0) {
              ckpzobj.pinHeader = data.cuttingMouthNeedleGrey[0].pinHeader
              ckpzobj.arrangement = data.cuttingMouthNeedleGrey[0].arrangement
              ckpzid.value = data.cuttingMouthNeedleGrey[0].cmdName
            }

            // 关联商品渲染
            pageData.spRowList = data.commodities
            pageData.spRowList.map((o: any) => {
              o.isban = true
            })
            // 排三角arrangementTriangleGreys
            sjdata.sj = data.arrangementTriangleGreys.info
            // sjdata.sjid=data.arrangementTriangleGreys.greyId
            // psjpb.value=data.arrangementTriangleGreys.greyId 现有坯布
            sjdata.atCode = data.arrangementTriangleGreys.atCode
            sjdata.atName = data.arrangementTriangleGreys.atName
            sjdata.remark = data.arrangementTriangleGreys.remark
            //psList.value = data.atOther
            if (data.atOther != '' && data.atOther != null) {
              psList.value = data.atOther
            }
            if (data.atOther == '' || data.atOther == null) {
              var aa = [] as any
              for (var i = 0; i < ylTableList.value.length + 1; i++) {
                var shuzu = [] as any
                for (var j = 0; j <= 2 + shikaishu.value; j++) {
                  if (i > 0 && j == 1) {
                    var obj2 = {
                      val: ylTableList.value[i - 1].yarnSource,
                      text: ylTableList.value[i - 1].staple,
                    }
                    shuzu.push(obj2)
                  }
                  if (i == 0 && j == 2) {
                    var obj = { val: '排纱' }
                    shuzu.push(obj)
                  }
                  if (i != 0 && j == 0) {
                    var obj = { val: '纱长(cm)' }
                    shuzu.push(obj)
                  }
                  if (i == 0 && j != 2) {
                    var obj3 = { val: '' }
                    shuzu.push(obj3)
                  }
                  if (i > 0 && j > 1) {
                    var obj3 = { val: '' }
                    shuzu.push(obj3)
                  }
                }

                aa.push(shuzu)
              }
              psList.value = aa
            }
          }
          if (sjdata.sj == undefined || sjdata.sj == null) {
            sjdata.sj = []
          }
          if (sjdata.sj.length == 0) {
          }
          if (sjdata.sj.length === 1) {
            dataForm.models = '1'
          } else {
            dataForm.models = '2'
          }
          numb.row = sjdata.sj.map((o: any) => {
            return o.typeData.length
          })
          let maxColNumber = 0
          //tw改
          maxColNumber = shikaishu.value
          numb.col = maxColNumber

          shikaishu.value = maxColNumber
          xhCol.value = []

          numb.col = shikaishu.value / xuanhuancihu.value
          var paishachang = 0
          if (data.atOther != '' && data.atOther != null) {
            paishachang = data.atOther[0].length - 3
          }
          if (data.atOther == '' || data.atOther == null) {
            paishachang = shikaishu.value
          }
          if (data.arrangementTriangleGreys.loopList?.length > 0) {
            xhCol.value = [
              {
                val: 0,
              },
            ]
            let onceCount = 0
            settingLoopData.value = data.arrangementTriangleGreys.loopList
            data.arrangementTriangleGreys.loopList.forEach((item: any) => {
              for (let index = item.wayStart; index < item.wayEnd + 1; index++) {
                xhCol.value.push({ val: index })

                onceCount += item.loopCount
              }
            })
            shikaishu.value = onceCount
          } else {
            xhCol.value = []
            for (let i = 0; i <= paishachang; i++) {
              xhCol.value.push({ val: i })
            }
          }
        })

        if (idToData.length > 0) {
          for (let key in idToData[0]) {
            dataForm[key] = idToData[0][key]
          }
        }

        ylId.value = ''

        //侧滑栏滑出滑入
        pageData.showAdd2 = true
        // setTimeout(()=>{jiShuanSha()},2000)
        pageData.sideTitle = '修改坯布'
        xhCol.value = []

        for (let i = 0; i <= numb.col; i++) {
          var obj = { val: i }
          xhCol.value.push(obj)
        }
      }

      const changeNeedleCount = (val: any) => {
        dataForm.needleCount = undefined
        dataForm.dimensionFigure = undefined
        dataForm.sumNeedleCount = undefined

        pageData.needleCountList.forEach(function (o: any) {
          if (o['model'] == val) {
            dataForm.needleCount = o['numberThreads']
            dataForm.dimensionFigure = o['smallNumber']
            dataForm.sumNeedleCount = o['sumNeedleNum']
            // dataForm.alwaysGoes = Number(o['sumWay'])
          }
        })
        getTheoreticalYield('')
      }

      const formRef = ref<FormInstance>()
      const formRef1 = ref()
      const sideOk = () => {
        if (dataForm.alwaysGoes == 0) {
          Message.warning({
            content: '工艺信息里总路数不能为0！',
            duration: 5000,
          })
          return
        }
        if (dataForm.theoreticalYield == 0 || dataForm.theoreticalYield == null) {
          Message.warning({
            content: '理论产能计算结果为0,请核对参数后重新计算！',
            duration: 5000,
          })
          return
        }
        let isBtx = false
        for (let index = 0; index < ylTableList.value.length; index++) {
          if (
            ylTableList.value[index]['yarnUnits'] == '' ||
            ylTableList.value[index]['yarnUnits'] == null ||
            ylTableList.value[index]['yarnCountProportion'] == '' ||
            ylTableList.value[index]['yarnCountProportion'] == null ||
            ylTableList.value[index]['yarnCountProportion'] == 0 ||
            ylTableList.value[index]['weavingDamage'] == '' ||
            ylTableList.value[index]['weavingDamage'] == 0 ||
            ylTableList.value[index]['weavingDamage'] == null ||
            ylTableList.value[index]['yarnLong'] == '' ||
            ylTableList.value[index]['yarnLong'] == 0 ||
            ylTableList.value[index]['wayNum'] == '' ||
            ylTableList.value[index]['wayNum'] == 0
          ) {
            Message.warning({
              content: '纱支结构页签内的红色单元格必填！且数字类型的不能为0',
              duration: 5000,
            })
            isBtx = true
            break
          }
        }
        if (isBtx) {
          return
        }

        var jj = [] as any
        sjdata.sj.map((o: any) => {
          if (o.show == true || o.show == undefined || o.show == null || o.show == '') {
            jj.push(o)
          }
        })
        let arrangementTriangle = {}
        if (sjdata.sj.length > 0) {
          arrangementTriangle = {
            atName: sjdata.atName,
            atCode: sjdata.atCode,
            remark: sjdata.atName,
            info: jj,
          }
        }

        formRef.value?.validate().then((err) => {
          formRef.value?.validate().then((err1) => {
            if (!err1) {
              if (!err) {
                console.log('zzpzdata.value', zzpzdata.value)
                pageData.pageLoading = true
                let data1 = {}
                data1['psj'] = {
                  atName: sjdata.atName,
                  atCode: sjdata.atCode,
                  remark: sjdata.atName,
                  info: sjdata.sj,
                }
                data1['ckpz'] = ckpzobj
                data1['zzpz'] = zzpzdata.value
                data1['yl'] = ylTableList.value
                data1['sp'] = ''
                // 拼接额外信息
                let ewsjArr: any[] = []
                ewsj.value.forEach((o: any) => {
                  ewsjArr = ewsjArr.concat(...o)
                })
                let organizationPinSon: any = {}

                if (data1['zzpz'] != null) {
                  let zzpzOb = zzpzListSelect.value.filter(
                    (item: any) => item.id == zzpzid.value
                  )[0]
                  const listParams = JSON.parse(JSON.stringify(data1['zzpz']))
                  listParams.forEach((item: any) => {
                    item.alignState = alignState.value[0] ? Number(alignState.value[0]) : ''
                  })
                  organizationPinSon = {
                    organizationName: zzpzOb == undefined ? '' : zzpzOb.organizationName,
                    list: listParams,
                  }
                }
                //循环用户选中的商品 取id
                let commodityGreyList: any = []
                pageData.spRowList.forEach(function (o: any) {
                  if (o['isban'] == true) {
                    commodityGreyList.push(o['id'])
                  }
                })

                //原料列表、
                let yarnStructure = ylTableList.value
                let greyInformations = dataForm
                ckpzobj.id = undefined
                if (
                  greyInformations['drawnNeedleState'] == '' ||
                  greyInformations['drawnNeedleState'] == null
                ) {
                  if (greyInformations['drawnNeedleState'] + '' !== '0') {
                    greyInformations['drawnNeedleState'] = 2
                  }
                }
                if (pageData.sideTitle === '新增坯布') {
                  //新增坯布
                  greyInformations['theoryPrice'] = theoryPrice.value
                  greyInformations['crossMemo'] = crossMemo.value
                  if (
                    arrangementTriangle['info'] != undefined &&
                    arrangementTriangle['info'] != null
                  ) {
                    arrangementTriangle['info'].map((o: any) => {
                      o.typeData.map((a: any) => {
                        a.needleList.map((b: any) => {
                          b.circulationNum = xuanhuancihu.value
                          b.realOpenNum = shikaishu.value
                        })
                      })
                    })
                  }
                  console.log(yarnStructure);
                  
                  // yarnStructure.forEach((item)=>{
                  //   item.yarnCountProportion=Number((item.yarnCountProportion).toFixed(2))
                  // })
                  arrangementTriangle['loopList'] = settingLoopData.value
                  post({
                    url: 'product/pdGreyInformation/insert',
                    data: {
                      arrangementTriangle,
                      organizationPinSon,
                      commodityGreyList,
                      yarnStructure,
                      greyInformations,
                      cuttingMouthNeedleGrey: ckpzobj,
                      atOther: psList.value,
                      // machineUnit: machineUnit.value,
                    },
                  })
                    .then((res: any) => {
                      if (res.code === 200) {
                        Message.success({
                          content: '新增成功',
                          duration: 5000,
                        })
                        machineUnit.value = 0
                        theoryPrice.value = 0
                        pageData.showAdd2 = false
                        alignState.value = ['0']
                        alignType.value = '0'
                        doRefresh()
                      } else {
                        Message.error({
                          content: res.message,
                          duration: 5000,
                        })
                      }
                    })
                    .finally(() => {
                      pageData.pageLoading = false
                    })
                } else if (pageData.sideTitle === '修改坯布') {
                  //修改
                  //tw加
                  greyInformations['theoryPrice'] = theoryPrice.value
                  greyInformations['crossMemo'] = crossMemo.value
                  greyInformations['id'] = id.value as any
                  if (
                    arrangementTriangle['info'] != undefined &&
                    arrangementTriangle['info'] != null
                  ) {
                    arrangementTriangle['info'].map((o: any) => {
                      o.typeData.map((a: any) => {
                        a.needleList.map((b: any) => {
                          b.circulationNum = xuanhuancihu.value
                          b.realOpenNum = shikaishu.value
                        })
                      })
                    })
                  }
                  arrangementTriangle['loopList'] = settingLoopData.value
                  post({
                    url: 'product/pdGreyInformation/insert',
                    data: {
                      arrangementTriangle,
                      organizationPinSon,
                      commodityGreyList,
                      yarnStructure,
                      greyInformations,
                      cuttingMouthNeedleGrey: ckpzobj,
                      atOther: psList.value,
                    },
                  })
                    .then(({ data, code, message }: any) => {
                      if (code === 200) {
                        formRef.value?.resetFields()
                        formRef1.value?.resetFields()
                        Message.success({
                          content: '修改成功',
                          duration: 5000,
                        })
                        doRefresh()
                        pageData.showAdd2 = false
                        alignState.value = ['0']
                        alignType.value = '0'
                      } else {
                        Message.error({
                          content: message,
                          duration: 5000,
                        })
                      }
                    })
                    .finally(() => {
                      pageData.pageLoading = false
                    })
                } else if (pageData.sideTitle === '复制新增') {
                  jinxingfuzhi()
                  pageData.pageLoading = false
                }
              }
            }
          })
        })
      }
      const deleteHandler = () => {
        if (shenhebiaoji.value == 1) {
          if (table1Ref.value.getSelectedRows().length === 0) {
            Message.error('请先勾选')
            return
          }
          Modal.confirm({
            title: '系统提示',
            content: '确认删除选中的数据?',
            draggable: true,
            onOk() {
              pageData.pageLoading = true
              post({
                url: 'product/pdGreyInformation/delete',
                data: table1Ref.value.getSelectedRows().map((o: any) => {
                  return o.id
                }),
              })
                .then(({ code, data, message }: any) => {
                  if (code === 200) {
                    Message.success({
                      content: '删除成功',
                      duration: 5000,
                    })
                    pagination.page = 1
                    doRefresh()
                  } else {
                    Message.error({
                      content: message,
                      duration: 5000,
                    })
                  }
                })
                .finally(() => {
                  pageData.pageLoading = false
                })
            },
          })
        } else {
          if (table2Ref.value.getSelectedRows().length === 0) {
            Message.error('请先勾选')
            return
          }
          Modal.confirm({
            title: '系统提示',
            content: '确认删除选中的数据?',
            draggable: true,
            onOk() {
              pageData.pageLoading = true
              post({
                url: 'product/pdGreyInformation/delete',
                data: table2Ref.value.getSelectedRows().map((o: any) => {
                  return o.id
                }),
              })
                .then(({ code, data, message }: any) => {
                  if (code === 200) {
                    Message.success({
                      content: '删除成功',
                      duration: 5000,
                    })
                    pagination.page = 1
                    doRefresh()
                  } else {
                    Message.error({
                      content: message,
                      duration: 5000,
                    })
                  }
                })
                .finally(() => {
                  pageData.pageLoading = false
                })
            },
          })
        }
      }
      //工厂 /编号/单位下拉框改变事件
      const changeFirm = () => {
        post({
          url: 'product/pdGreyInformation/selectpdGreyInformation',
          data: {
            firm: queryData.firm,
          },
        })
          .then(({ data, code }: any) => {
            if (code === 200) {
              table.handleSuccess(data.list)
              pagination.setTotalSize(data.total)
            }
          })
          .catch(console.log)
      }
      //设置循环路数按钮点击事件:原来
      const addCol = () => {
        RendPs(2)
        let maxColNumber = 0
        addFlag.value = 1
        sjdata.sj[0].typeData[0].needleList.forEach((o: any) => {
          if (o.way > maxColNumber) {
            maxColNumber = parseInt(o.way)
          }
        })
        //let n = maxColNumber - numb.col
        let n = maxColNumber - shikaishu.value
        if (n < 0) {
          for (let i = n; i < 0; i++) {
            sjdata.sj.forEach((o: any) => {
              o.typeData.forEach((o1: any, id: number) => {
                o1.needleList.push({
                  way: maxColNumber + Math.abs(n - i) + 1,
                  needle: '',
                })
              })
            })

            for (let k = 0; k < psList.value.length; k++) {
              // for (let j = 0; j < psList.value[k].length; j++) {
              psList.value[k].push({ val: '' })
              // }
            }
          }
        } else if (n > 0) {
          for (let i = 0; i < n; i++) {
            sjdata.sj.forEach((o: any, i: number) => {
              o.typeData.forEach((o1: any) => {
                o1.needleList.pop()
              })
            })
            for (let k = 0; k < psList.value.length; k++) {
              // for (let j = 0; j < psList.value[k].length; j++) {
              psList.value[k].pop()
              // }
            }
          }
        } else {
          return
        }
        xhCol.value = []
        // for (let i = 0; i <= numb.col; i++) {
        //     xhCol.value.push({ val: i })
        // }
        for (let i = 0; i <= numb.col; i++) {
          xhCol.value.push({ val: i })
        }
      }

      const subCol = () => {
        if (sjdata.sj[0].typeData[0].needleList.length === 1) {
          Message.warning('请至少保留一位路数！')
          return
        }
        sjdata.sj.forEach((o: any, i: number) => {
          o.typeData.forEach((o1: any) => {
            o1.needleList.pop()
          })
        })
      }
      const addRow = (item: any[]) => {
        // 现有多少行
        let maxRowNumber = 0
        item['typeData'].forEach((o: any) => {
          if (o.serialNumber > maxRowNumber) {
            maxRowNumber = o.serialNumber
          }
        })
        let index = sjdata.sj.indexOf(item)
        let n = maxRowNumber - numb.row[index]
        if (n < 0) {
          for (let i = n; i < 0; i++) {
            let nl: any[] = []
            item['typeData'][0].needleList.forEach((o: any) => {
              nl.push({
                way: o.way,
                needle: '',
              })
            })
            item['typeData'].push({
              serialNumber: maxRowNumber + Math.abs(n - i) + 1,
              needleName: '',
              needleList: nl,
            })
          }
        } else if (n > 0) {
          for (let i = 0; i < n; i++) {
            item['typeData'].pop()
          }
        }
      }
      const subRow = (item: any[]) => {
        if (item.length === 1) {
          Message.warning('请最少保留一行！')
          return
        }
        item.pop()
      }

      // 禁止input 只能输入整数
      function setNum(val: any) {
        if (val.upBasin === undefined || parseInt(val.upBasin) + '' === 'NaN') {
          val.upBasin = ''
        } else {
          val.upBasin = parseInt(val.upBasin)
        }
      }

      function setNum1(val: any) {
        if (val.belowBasin === undefined || parseInt(val.belowBasin) + '' === 'NaN') {
          val.belowBasin = ''
        } else {
          val.belowBasin = parseInt(val.belowBasin)
        }
      }

      const tagValue = ref<string>(pageData.tags[0].id)

      const setSJValue = (i2: any, item: any) => {
        // if (dataForm.machineType == "双面机" || dataForm.machineType == "螺纹机") {
        if (item.type == '上盘') {
          if (tagValue.value == '1' || tagValue.value == '3' || tagValue.value == '5') {
            i2.needle = tagValue.value
          } else {
            Message.warning({
              content: dataForm.machineType + '上盘Ո,Ʌ不可选择',
              duration: 5000,
            })
            return
          }
        } else if (item.type == '下盘') {
          if (tagValue.value == '1' || tagValue.value == '2' || tagValue.value == '4') {
            i2.needle = tagValue.value
          } else {
            Message.warning({
              content: dataForm.machineType + '下盘Ս,V不可选择',
              duration: 5000,
            })
            return
          }
        }
        // } else {
        //     i2.needle = tagValue.value
        // }
      }
      const gridOption = ref()
      const colState = ref()
      const gridReady = (params: any) => {
        gridOption.value = params.api
        colState.value = params.columnApi
      }
      const gridOption2 = ref()
      const colState2 = ref()
      const gridReady2 = (params: any) => {
        gridOption2.value = params.api
        colState2.value = params.columnApi
      }
      const sdataForm = reactive({
        atName: '',
        id: '',
        remark: '',
        firm: '',
        atCode: '',
        arrangement: '',
        deleteState: '',
        obsoleteState: '',
        createName: '',
        createTime: '',
        updateName: '',
        updateTime: '',
      })
      const numb = reactive<{ row: number[]; col: number }>({
        row: [1, 1],
        col: 1,
      })
      const sm = ref<string>('1')
      watch(
        () => dataForm.models,
        (val, oldValue) => {
          if (val === '1') {
            //-numb.col = 1;
            shikaishu.value = 1
            numb.row = [1, 1]

            //单面机
            if (sjdata.sj.length === 2) {
              //切换删上盘
              sjdata.sj.splice(0, 1)
              sjdata.sj[0] = {
                type: '下盘',
                typeData: [
                  {
                    serialNumber: 1,
                    needleName: '',
                    needleList: [{ way: 1 }],
                  },
                ],
              }
            }
          } else {
            //双面机
            if (sjdata.sj.length === 1) {
              //numb.col = 1;
              shikaishu.value = 1
              numb.row = [2, 4]
              let maxColNumber = 0
              sjdata.sj[0].typeData[0].needleList.forEach((o: any) => {
                if (o.way > maxColNumber) {
                  maxColNumber = parseInt(o.way)
                }
              })
              const list = []
              for (let i = 0; i < maxColNumber; i++) {
                list.push({
                  needle: tagValue.value,
                  way: 1,
                })
              }
              sjdata.sj.splice(0, 0, {
                type: '上盘',
                typeData: [
                  {
                    serialNumber: 1,
                    needleName: '',
                    needleList: [
                      {
                        needle: '',
                        way: 1,
                      },
                    ],
                  },
                  {
                    serialNumber: 2,
                    needleName: '',
                    needleList: [
                      {
                        needle: '',
                        way: 1,
                      },
                    ],
                  },
                ],
              })
              sjdata.sj[1]['typeData'] = []
              sjdata.sj[1]['typeData'].push(
                {
                  serialNumber: 1,
                  needleName: '',
                  needleList: [
                    {
                      needle: '',
                      way: 1,
                    },
                  ],
                },
                {
                  serialNumber: 2,
                  needleName: '',
                  needleList: [
                    {
                      needle: '',
                      way: 1,
                    },
                  ],
                },
                {
                  serialNumber: 3,
                  needleName: '',
                  needleList: [
                    {
                      needle: '',
                      way: 1,
                    },
                  ],
                },
                {
                  serialNumber: 4,
                  needleName: '',
                  needleList: [
                    {
                      needle: '',
                      way: 1,
                    },
                  ],
                }
              )
            }
          }
        }
      )
      const sjhasnull = (): { way: number; type: string } | undefined => {
        let d: { way: number; type: string } | undefined = undefined
        sjdata.sj.forEach((o) => {
          o.typeData.forEach((o1: any) => {
            o1.needleList.forEach((o2: any) => {
              if (o2.needle == '' || o2.needle === undefined || o2.needle == null) {
                d = { way: o2.way, type: o.type }
                return false
              }
            })
          })
        })
        return d
      }
      const blList = ref<any[]>([])
      const focusBl = () => {
        post({
          url: 'product/mercery/getList',
          data: {
            merceryName: '',
            deleteState: '0',
          },
        }).then(({ code, data }) => {
          if (code === 200) {
            blList.value = data
          }
        })
      }
      const blSelect = (v: string) => {
        post({
          url: 'product/mercery/getList',
          data: {
            merceryName: v,
            deleteState: '0',
          },
        }).then(({ code, data }) => {
          if (code === 200) {
            blList.value = data
          }
        })
      }
      post({
        url: 'product/mercery/getList',
        data: {
          merceryName: '',
          deleteState: '0',
        },
      }).then(({ code, data }) => {
        if (code === 200) {
          blList.value = data
        }
      })

      const szList = ref<any[]>([])

      const szSelect = (v: string) => {
        let type = typeof v
        if (type == 'object') {
          v = ''
        }
        // post({
        //     url: 'product/yarnType/getList',
        //     data: {
        //         "typeName": v,
        //         "deleteState": "0"
        //     }
        // }).then(({ code, data }) => {
        //     if (code === 200) {
        //         szList.value = data
        //     }
        // })

        //纱线类别
        post({
          url: 'product/Yarn/getFieldValue',
          data: {
            yarnName: v,
          },
        }).then(({ code, data }) => {
          if (code === 200) {
            szList.value = data
          }
        })
      }

      const gnList = ref<any[]>([])
      const focusGn = () => {
        post({
          url: 'product/greyInformationData/select',
          data: {
            greyInformationName: '',
            deleteState: '0',
          },
        }).then(({ code, data }) => {
          if (code === 200) {
            gnList.value = data
          }
        })
      }
      const gnSelect = (v: string) => {
        post({
          url: 'product/greyInformationData/select',
          data: {
            greyInformationName: v,
            deleteState: '0',
          },
        }).then(({ code, data }) => {
          if (code === 200) {
            gnList.value = data
          }
        })
      }

      post({
        url: 'product/greyInformationData/select',
        data: {
          greyInformationName: '',
          deleteState: '0',
        },
      }).then(({ code, data }) => {
        if (code === 200) {
          gnList.value = data
        }
      })
      const codeGen = () => {
        if (
          dataForm.mercery !== '' &&
          dataForm.feature !== '' &&
          dataForm.yarnCountCategory !== ''
        ) {
          let gnCode = gnList.value.filter((ob: any) => {
            return ob.greyInformationName === dataForm.feature
          })[0]?.greyInformation

          // let szCode = szList.value.filter((ob: any) => {
          //     return ob.typeName === dataForm.yarnCountCategory
          // })[0].typeCode
          let szCode = szList.value.filter((ob: any) => {
            return ob.yarnName === dataForm.yarnCountCategory
          })[0]?.yarnCode
          let blCode = blList.value.filter((ob: any) => {
            return ob.merceryName === dataForm.mercery
          })[0]?.merceryCode
          post({
            url: 'product/pdGreyInformation/getPbbh',
            data: {
              processType: dataForm.processType,
              gncode: gnCode,
              szcode: szCode,
              blcode: blCode,
              greyCode: '',
              fromGreyCode: '',
              copyType: '',
            },
          }).then(({ code, data }) => {
            if (code === 200) {
              dataForm.greyCode = data
            }
          })
        }

        getGrayFabricName()
      }
      const codeGens = (val: any) => {
        console.log(val)
        if (
          dataForm.mercery !== '' &&
          dataForm.feature !== '' &&
          dataForm.yarnCountCategory !== ''
        ) {
          let gnCode = gnList.value.filter((ob: any) => {
            return ob.greyInformationName === dataForm.feature
          })[0]?.greyInformation

          // let szCode = szList.value.filter((ob: any) => {
          //     return ob.typeName === dataForm.yarnCountCategory
          // })[0].typeCode
          let szCode = szList.value.filter((ob: any) => {
            return ob.yarnName === dataForm.yarnCountCategory
          })[0]?.yarnCode
          let blCode = blList.value.filter((ob: any) => {
            return ob.merceryName === dataForm.mercery
          })[0]?.merceryCode
          if (shenhebiaoji.value == 1) {
            post({
              url: 'product/pdGreyInformation/getPbbh',
              data: {
                processType: dataForm.processType,
                gncode: gnCode,
                szcode: szCode,
                blcode: blCode,
                greyCode: table1Ref.value.getSelectedRows()[0].greyCode,
                fromGreyCode: '',
                copyType: fuzhixinzengindex.value,
              },
            }).then(({ code, data }) => {
              if (code === 200) {
                dataForm.greyCode = data
                dataForm.grayFabricName = val
              }
            })
          } else {
            post({
              url: 'product/pdGreyInformation/getPbbh',
              data: {
                processType: dataForm.processType,
                gncode: gnCode,
                szcode: szCode,
                blcode: blCode,
                greyCode: table2Ref.value.getSelectedRows()[0].greyCode,
                fromGreyCode: '',
                copyType: fuzhixinzengindex.value,
              },
            }).then(({ code, data }) => {
              if (code === 200) {
                dataForm.greyCode = data
                dataForm.grayFabricName = val
              }
            })
          }
        }

        getGrayFabricName()
      }
      const psjpb = ref<any>()
      const psjpblist = ref<any[]>([])
      const psjpblistSelect = (v: any) => {
        let isOb: any = typeof v
        let val = v
        if (isOb == 'object') {
          val = ''
        }

        post({
          url: 'product/pdGreyInformation/getFieldValue',
          data: {
            greyCode: val,
            machineType:
              dataForm.machineType == null
                ? undefined
                : dataForm.machineType == ''
                ? undefined
                : dataForm.machineType,
          },
        }).then(({ code, data }) => {
          if (code === 200) {
            psjpblist.value = data
          }
        })
      }
      // 从旧坯布获取排三角信息
      const psjpbOk = () => {
        if (psjpb.value === '' || psjpb.value === null || psjpb.value === undefined) {
          Message.warning('请先选择坯布！')
          return
        }
        post({
          url: 'product/arrangementTriangleGrey/getGreyAtInfoByGreyId?id=' + psjpb.value,
        }).then(({ code, data, message }: any) => {
          if (code === 200) {
            if (JSON.stringify(data) === '{}') {
              Message.warning('此坯布无排三角信息！')
              return
            }
            huancunpanduanziduan.value = ''
            let info = data.info
            xuanzepaisanjiaolist.value = data.info

            if (info.length > 0) {
              if (info[0].typeData.length > 0) {
                getWayNum()
                // dataForm.theoreticalYield == 0
                //  numb.col = (info[0].typeData[0].needleList).length;
                // shikaishu.value = info[0].typeData[0].needleList.length
                // xuanhuancihu.value = 1
                numb.col = info[0].typeData[0].needleList.length
                info.map((o: any, index: any) => {
                  numb.row[index] = o.typeData.length
                })
                xuanhuancihu.value = info[0].typeData[0].needleList[0].circulationNum
                shikaishu.value = info[0].typeData[0].needleList[0].realOpenNum
                // shikaishu.value = numb.col
              } else {
                //  numb.col = 1;
                // shikaishu.value = 1
              }
            } else {
              // numb.col = 1;
              // shikaishu.value = 1
            }

            // for (let i = 0; i <= numb.col; i++) {
            //   xhCol.value.push({ val: i })
            // }
            if (data.loopList.length > 0) {
              xhCol.value = [
                {
                  val: 0,
                },
              ]
              let onceCount = 0
              settingLoopData.value = data.loopList
              data.loopList.forEach((item: any) => {
                for (let index = item.wayStart; index < item.wayEnd + 1; index++) {
                  xhCol.value.push({ val: index })

                  onceCount += item.loopCount
                }
              })
              shikaishu.value = onceCount
            } else {
              xhCol.value = []
              for (let i = 0; i <= numb.col; i++) {
                xhCol.value.push({ val: i })
              }
            }

            //排纱 数据
            RendPs(2)
            sjdata.sjid = ''
            sjdata.atCode = data.atCode
            sjdata.atName = data.atName
            sjdata.remark = data.remark
            sjdata.sj = data.info
            if (sjdata.sj.length === 1) {
              dataForm.models = '1'
            } else {
              dataForm.models = '2'
            }
            if (data.loopList?.length > 0) {
              settingLoopData.value = data.loopList
            } else {
              settingLoopData.value = []
            }
            addFlag.value = 4
          } else {
            Message.error(message)
          }
        })
      }
      const sp = reactive<any>({
        spdata: {},
      })
      // 商品下拉列表
      const spSelectList = ref<any[]>([])
      const focusSp = () => {
        spSelect('')
      }
      const options5 = ref<any>(spSelectList)
      const loading5 = ref(false)
      const handleSearch5 = (value: any) => {
        if (value) {
          loading5.value = true

          spSelect(value)
          options5.value = spSelectList
          loading5.value = false
        } else {
          options5.value = []
        }
      }

      // 商品下拉查询
      const spSelect = (v: string) => {
        post({
          url: 'product/Commodity/getList',
          data: {
            commodityName: v,
            deleteState: 0,
            assertState: 0,
          },
        }).then(({ code, data }) => {
          spSelectList.value = data
        })
      }
      //添加商品的行数据
      const addSpRow = () => {
        //判断是否选择了商品
        if (sp.id == undefined || sp.id == '') {
          Message.warning('请选择一个商品再添加！！')
          return
        }
        // 判断商品是否被选择过
        let tempList = pageData.spRowList.filter(function (o: any) {
          return o['id'] == sp.id
        })
        if (tempList.length > 0) {
          Message.warning('选择的商品已被添加过,请勿重复添加!')
          return
        }
        //将选择的商品筛选出来
        let spList = spSelectList.value.filter(function (o: any) {
          return o['id'] == sp.id
        })
        if (spList.length > 0) {
          pageData.spRowList.push(spList[0])
        }
        pageData.spRowList.map((o: any) => {
          if ((o.isban = undefined || o.isban == null || o.isban == '')) {
            o.isban = true
          }
        })
      }
      let selectedRowKeysSp = ref()
      //删除商品的行数据
      const delSpRow = () => {
        if (selectedRowKeysSp.value.length == 0) {
          Message.warning('请勾选一行！！')
          return
        }
        pageData.spRowList = pageData.spRowList.filter(function (o: any) {
          return !selectedRowKeysSp.value.includes(o['id'])
        })
        selectedRowKeysSp.value = []
      }

      const sptablecol: any = [
        {
          dataIndex: 'commodityCode',
          key: 'commodityCode',
          title: '商品编码',
        },
        {
          dataIndex: 'commodityName',
          key: 'commodityName',
          title: '商品名称',
        },
        {
          dataIndex: 'isban',
          key: 'isban',
          title: '是否启用',
          slotName: 'isban',
        },
        //  {
        //     dataIndex: 'brandName',
        //     key: 'brandName',
        //     title: '品牌'
        // }, {
        //     dataIndex: 'colorType',
        //     key: 'colorType',
        //     title: '染色类型'
        // },
        {
          dataIndex: 'merceryName',
          key: 'merceryName',
          title: '布料名称',
        },
        // {
        //   dataIndex: 'productType',
        //   key: 'productType',
        //   title: '产品类型',
        // },
      ]

      //排纱
      let psList = ref<any[]>([])
      //循环批量修改的数据构造
      let psEditList = ref<any[]>([])
      //装勾选的列的列数
      let checkedCol: any = []
      //改变勾的序号
      const changeXh = (val: any, num: any) => {
        psEditList.value = []
        //所有行的第几列 num i行数
        if (val.target.checked) {
          let realNum = num + 2
          if (!checkedCol.includes(realNum)) {
            checkedCol.push(realNum)
          }
          for (let i = 0; i < psList.value.length; i++) {
            // let ob={}
            let ob = ''
            if (i == 0) {
              if (moreEdit[psList.value[i][2]['val'] + '_' + i] == undefined) {
                moreEdit[psList.value[i][2]['val'] + '_' + i] = psList.value[i][realNum]['val']
              }
              ob = psList.value[i][2]['val']
              // ob[psList.value[i][2]['val']]=""
              // ob[psList.value[i][2]['val']]=psList.value[i][realNum]['val']
            } else {
              let key = psList.value[i][0]['val'] + psList.value[i][1]['val'] + '_' + i
              let key1 = psList.value[i][0]['val'] + psList.value[i][1]['val']
              if (moreEdit[key] == undefined) {
                moreEdit[key] = psList.value[i][realNum]['val']
              }
              ob = key1
              // ob[key1]=""
              // ob[key1]=psList.value[i][realNum]['val']
            }
            psEditList.value.push(ob)
          }
        }
      }
      const visible = ref(false)
      //批量修改的弹窗
      const handleClick = () => {
        if (Object.keys(moreEdit).length > 0) {
          visible.value = true
        } else {
          Message.error('请先勾选列！')
        }
      }
      const handleBeforeOk = () => {
        //将修改的值渲染回列表里
        for (let key in moreEdit) {
          let rowNum = key.split('_')[1]
          for (let j = 0; j < checkedCol.length; j++) {
            psList.value[parseFloat(rowNum)][checkedCol[j]].val = moreEdit[key]
          }
        }
        getWayNum()
        // console.log(checkedCol.length, '2222222') // 勾选的条数
        let inputCheck: any = document.getElementsByClassName('inputCheck')
        for (let i = 0; i < inputCheck.length; i++) {
          inputCheck[i].checked = false
        }
        checkedCol = []

        //tw加清空批量修改框的值
        for (let item in moreEdit) {
          moreEdit[item] = ''
        }
      }
      const handleCancel = () => {
        visible.value = false
        for (let key in moreEdit) {
          delete moreEdit[key]
        }
        let inputCheck: any = document.getElementsByClassName('inputCheck')
        for (let i = 0; i < inputCheck.length; i++) {
          inputCheck[i].checked = false
        }
        checkedCol = []
      }
      let moreEdit = reactive<any>({})
      //拖拽
      const handleChange = (_data: any) => {
        table.handleSuccess(_data)
      }
      //关闭弹窗时初始化数据
      const cancelPop = () => {
        pageData.showAdd2 = false
        psList.value = []
        xhCol.value = []
        pageData.ylCfIdList = []
        theoryPrice.value = 0
        machineUnit.value = 0
      }
      const defaultColDef = {
        sortable: true,
        resizable: true,
        filter: true,
        // flex: 1
      }
      //添加原料表格
      let selectedRowKeysAddYl = ref()

      const visible1 = ref(false)
      //添加原料的弹窗
      const handleClick1 = () => {
        visible1.value = true
        ylData.value.rawmaterialCode = ''
        ylData.value.materialsName = ''
        ylData.value.yarnCount = ''
      }

      const handleCancel1 = () => {
        visible1.value = false
        selectedRowKeysAddYl.value = []
        pageData.ylRowList = []
      }
      //查询要添加的有原料
      const cxYlList = () => {
        post({
          url: 'product/Rawmaterial/getInfoPage',
          data: {
            ...ylData.value,
            page: fySelet4.page,
            size: fySelet4.size,
          },
        }).then(({ code, data }) => {
          if (code == 200) {
            pageData.ylRowList = data.list
            fySelet4.total = data.total
          } else {
            Message.error('查询失败！')
          }
        })
      }
      const ylColumns: any = [
        {
          dataIndex: 'yarnCode',
          key: 'yarnCode',
          title: '原料编号',
        },
        {
          dataIndex: 'staple',
          key: 'staple',
          title: '原料名称',
        },
        {
          dataIndex: 'colorType',
          key: 'colorType',
          title: '原料类别',
        },
        {
          dataIndex: 'merceryName',
          key: 'merceryName',
          title: '纱支',
        },
        {
          dataIndex: 'productType',
          key: 'productType',
          title: '纱支类别',
        },
        {
          dataIndex: 'processType',
          key: 'processType',
          slotName: 'processType',
          title: '是否本集团',
        },
      ]
      //添加原料列表的表单数据
      let ylData = ref({
        materialsName: '',
        rawmaterialCode: '',
        yarnCount: '',
        auditState: 1,
        processType: 0,
      })

      //添加原料模糊搜索
      //下拉框得到焦点
      let selParam: any = ''
      const focusSelYl = (val: any) => {
        const ob = {}
        ob[val] = ''
        ob['auditState'] = 1
        selCxAllYl(ob)
        selParam = val
      }
      //下拉数据  坯布编号
      const optionsYl = ref<any>(pageData.codeList)
      const handleSearchYl = (value: any) => {
        if (value) {
          const ob = {}
          ob[selParam] = value
          loading.value = true
          selCxAllYl(ob)
          optionsYl.value = pageData.codeList
          loading.value = false
        } else {
          optionsYl.value = []
        }
      }

      //下拉框查询 坯布编号
      function selCxAllYl(val: any) {
        post({
          url: 'product/Rawmaterial/getRawmaterialsNameDrop',
          data: val,
        }).then(({ data, code, message }: any) => {
          if (code === 200) {
            if (selParam == 'materialsName') {
              pageData.materialsNameList = data
            } else if (selParam == 'rawmaterialCode') {
              pageData.rawmaterialCodeList = data
            } else if (selParam == 'yarnCount') {
              pageData.yarnCountList = data
            }
          } else {
            Message.error({
              content: message,
              duration: 5000,
            })
          }
        })
      }

      //判断开发编号规则
      const ExploitCodeRules = (value: string, cb: Function) => {
        return new Promise<void>((resolve) => {
          if (value != undefined) {
            if (value.length != 10 && !value.startsWith('JFK')) {
              cb('开发编号规则:JFK+年份2前位+月份2位+3位流水号！例如:JFK2211615')
            }
          }
          resolve()
        })
      }
      //判断备案编号规则
      const putOnRecordsCodeRules = (value: string, cb: Function) => {
        return new Promise<void>((resolve) => {
          if (value != undefined) {
            if (value.length != 14 && !value.startsWith('PBML')) {
              cb('备案编号规则:PBML+年份2前位+月份2位+日期2位+4位流水号！例如:PBML2212130006')
            }
          }
          resolve()
        })
      }
      //drawnNeedleStateRules
      const fabricTypeList = ref<any[]>([])
      const fabricTypeLoading = ref(false)
      const fabricTypeSelect = (value: any) => {
        if (value) {
          fabricTypeLoading.value = true
          getFabricTypeList(value)
          fabricTypeLoading.value = false
        }
      }
      const fabricTypeFocus = () => {
        getFabricTypeList('')
      }
      const getFabricTypeList = (val: any) => {
        post({
          url: 'product/pdFabric/getFieldValue',
          data: {
            fabricType: val,
            deleteState: 0,
          },
        }).then(({ code, data }) => {
          if (code === 200) {
            fabricTypeList.value = data
          }
        })
      }
      //判断此列是否大于100
      const totalOnehundred = (row: any, field: any) => {
        let nums = 0
        ylTableList.value.forEach(function (o: any) {
          if (o[field] != undefined && o[field] != null && o[field] != '') {
            nums += parseFloat(o[field])
          }
        })
        isshow.value = true
        if (nums > 100) {
          isshow.value = false
          Message.warning({
            content: '此列不能超过100',
            duration: 5000,
          })
          row[field] = 0
        }

        var aa = row.actualYarn - row.yarnCountProportion

        if (isNaN(aa)) {
          row.jieguo = 0 //其中一个或两个没选中的结果
          return
        }
        // var bb=shabilist.value.map((o:any,index:any)=>{
        //     if(aa>=Number(o.yarnCountMin)&&aa<=Number(o.yarnCountMax)){
        //         //在范围内
        //         return 1;
        //     }else if(aa<Number(o.yarnCountMin)||aa>Number(o.yarnCountMax)){
        //       return 2;
        //     }
        // })
        for (let item of shabilist.value) {
          if (aa >= Number(item['yarnCountMin']) && aa <= Number(item['yarnCountMax'])) {
            row.jieguo = 1
            break
          } else {
            row.jieguo = 2
          }
        }
      }

      const isEng = (record: any, value: any) => {
        var isletter = /^[a-zA-Z]+$/.test(value)
        if (!isletter) {
          Message.warning({
            content: '填写的值只能是英文！',
            duration: 5000,
          })
          record.colorGroup = ''
        } else {
          record.colorGroup = value.toUpperCase()
        }
      }

      let jgCxArray: any = ref([])

      function focusJgCx() {
        jgCx('')
      }

      const jgCx = (ob: any) => {
        if (typeof ob == 'object') {
          ob = ''
        }
        post({
          url: 'pdm/rubberhoseSet/getInfoDropValue',
          data: {
            rubberhoseName: ob,
          },
        }).then((res: any) => {
          if (res.code == 200) {
            jgCxArray.value = res.data
          }
        })
      }
      const localeText1: any = ref(localeText)

      //取到所有排纱下拉框
      function focusPs() {
        post({
          url: 'dict/dictTypeDetail/getListByCodeType?codeType=19',
        }).then((res: any) => {
          if (res.code == 200) {
            pageData.psDataList = res.data
          }
        })
      }

      const huiche = () => {
        doRefresh()
      }

      //纱长规则 路数规则
      function YarnLengthRule() {
        pageData.wayList = []
        dataForm.yarnLength = ''
        let row = psList.value
        for (var i = 1; i < row.length; i++) {
          let col = row[i]
          // let field = ''
          // for (var j = 3; j < col.length; j++) {
          //   if (col[j]['val'] != '' && col[j]['val'] != undefined && col[j]['val'] != null) {
          //     field = col[j]['val']
          //     break
          //   }
          // }
          var index1 = ''
          var index2 = ''
          if (col[1]['val'] != undefined && col[1]['val'] != null) {
            index1 = col[1]['val']
          }
          if (col[2]['val'] != undefined && col[2]['val'] != null) {
            index2 = col[2]['val']
          }

          if (dataForm.yarnLength == '') {
            dataForm.yarnLength =
              index1 +
              ':' +
              (index2 == undefined ? '' : index2) +
              '=' +
              (ylTableList.value[i - 1]['yarnLong'] == undefined
                ? ''
                : ylTableList.value[i - 1]['yarnLong']) +
              'CM'
          } else {
            dataForm.yarnLength +=
              ',' +
              index1 +
              ':' +
              (index2 == undefined ? '' : index2) +
              '=' +
              (ylTableList.value[i - 1]['yarnLong'] == undefined
                ? ''
                : ylTableList.value[i - 1]['yarnLong']) +
              'CM'
          }
          // //上纱路数
          // let numberTimes = 0
          // for (let j = 3; j < col.length; j++) {
          //   if (col[j]['val'] != "") {
          //     numberTimes++
          //   }
          // }
          // pageData.wayList.push(numberTimes)
        }
        // if (xuanhuancihu.value != null && xuanhuancihu.value != 0 && pageData.wayList.length != 0) {
        //   ylTableList.value.forEach(function (o: any, index: number) {
        //     o['wayNum'] = xuanhuancihu.value * pageData.wayList[index]
        //   })
        // }
      }

      //路数渲染  循环次数*排纱第四列开始不为空的个数
      function getWayNum() {
        if (settingLoopData.value.length > 0) {
          pageData.wayList = []

          let table = psList.value
          let settingLoopCountArr: any = []
          const rangeArr: any = []
          settingLoopData.value.forEach((item: any) => {
            rangeArr.push(item.wayEnd - item.wayStart + 1)
            for (let index = item.wayStart; index < item.wayEnd + 1; index++) {
              settingLoopCountArr.push(item.loopCount)
            }
          })

          for (var i = 1; i < table.length; i++) {
            let row = table[i]
            //上纱路数
            let numberTimes = 0
            for (let j = 3; j < row.length; j++) {
              let cellVal = row[j].val == '' ? 0 : 1
              numberTimes += settingLoopCountArr[j - 3] * cellVal
              console.log(j, cellVal, settingLoopCountArr[j - 3])
            }
            ylTableList.value[i - 1].wayNum = numberTimes
          }
          getTheoreticalYield('')
        } else {
          pageData.wayList = []

          let row = psList.value
          for (var i = 1; i < row.length; i++) {
            let col = row[i]
            //上纱路数
            let numberTimes = 0
            for (let j = 3; j < col.length; j++) {
              if (col[j]['val'] != '') {
                numberTimes++
              }
            }
            pageData.wayList.push(numberTimes)
          }
          if (
            xuanhuancihu.value != null &&
            xuanhuancihu.value != 0 &&
            pageData.wayList.length != 0
          ) {
            ylTableList.value.forEach(function (o: any, index: number) {
              o['wayNum'] = xuanhuancihu.value * pageData.wayList[index]
            })
          }

          getTheoreticalYield('')
        }
      }

      const jixing = () => {
        if (dataForm.machineType == '单面机') {
          pageData.tags = [
            { id: '1', val: '̶' },
            { id: '2', val: 'Ո' },
            { id: '4', val: 'Ʌ' },
          ]
          sjdata.sj = [
            {
              type: '下盘',
              typeData: [
                {
                  serialNumber: 1,
                  needleName: '',
                  needleList: [{ way: 1 }],
                },
                {
                  serialNumber: 2,
                  needleName: '',
                  needleList: [
                    {
                      needle: '',
                      way: 1,
                    },
                  ],
                },
                {
                  serialNumber: 3,
                  needleName: '',
                  needleList: [
                    {
                      needle: '',
                      way: 1,
                    },
                  ],
                },
                {
                  serialNumber: 4,
                  needleName: '',
                  needleList: [
                    {
                      needle: '',
                      way: 1,
                    },
                  ],
                },
              ],
            },
          ]
        } else {
          pageData.tags = [
            { id: '1', val: '̶' },
            { id: '2', val: 'Ո' },
            { id: '3', val: 'Ս' },
            {
              id: '4',
              val: 'Ʌ',
            },
            {
              id: '5',
              val: 'V',
            },
          ]
          sjdata.sj = [
            {
              type: '上盘',
              typeData: [
                {
                  serialNumber: 1,
                  needleName: '',
                  needleList: [
                    {
                      needle: '',
                      way: 1,
                    },
                  ],
                },
                {
                  serialNumber: 2,
                  needleName: '',
                  needleList: [
                    {
                      needle: '',
                      way: 1,
                    },
                  ],
                },
              ],
            },
            {
              type: '下盘',
              typeData: [
                {
                  serialNumber: 1,
                  needleName: '',
                  needleList: [{ way: 1 }],
                },
                {
                  serialNumber: 2,
                  needleName: '',
                  needleList: [
                    {
                      needle: '',
                      way: 1,
                    },
                  ],
                },
                {
                  serialNumber: 3,
                  needleName: '',
                  needleList: [
                    {
                      needle: '',
                      way: 1,
                    },
                  ],
                },
                {
                  serialNumber: 4,
                  needleName: '',
                  needleList: [
                    {
                      needle: '',
                      way: 1,
                    },
                  ],
                },
              ],
            },
          ]
        }

        //使机型和组织排针关联
        // if (dataForm.machineType == "双间螺纹机" || dataForm.machineType == "螺纹机") {
        //     zzpzid.value = 37
        // } else if (dataForm.machineType == "双面机") {
        //     zzpzid.value = 44
        // } else if (dataForm.machineType == "单面机") {
        //     zzpzid.value = 38
        // }
        psList.value = []
        xhCol.value = []
        shuaxinpaisha()
      }

      const duiqiheight = ref(35)
      const xuanhuancihu = ref(1)
      const shikaishu = ref(1)
      const xunhuan = (val: any) => {
        if (val == '循环' || val == '实开') {
          shikaishu.value = Number(xuanhuancihu.value) * Number(numb.col)
        }
        getWayNum()
      }
      const getwuliao = (val: any) => {
        if (typeof val == 'string') {
          val = { materialName: val, auditState: 1 }
        }
        post({
          url: 'purchase/MaterialInfo/getFieldValue',
          data: val,
        }).then(({ data, code }: any) => {
          if (code === 200) {
            // (data as string[]).splice(0, 0, "全部");
            //pageData.wuliaoname = data;
            //sessionStorage.setItem("物料名称",JSON.stringify(wuliaoname.value))
            wuliaoname.value = data
          } else {
            Message.error({
              content: '查询失败！',
              duration: 5000,
            })
          }
        })
      }
      const wuliaoname = ref([]) as any
      const gaibian = (key: any) => {
        psList.value.forEach((o: any, index: any) => {
          ylTableList.value.forEach((b: any, index2: any) => {
            if (index > 0) {
              if (index - 1 == index2) {
                if (b.yarnSource != '') {
                  if (o[1].val != undefined) {
                    if (o[1].val == b.yarnSource) {
                      o[1].text = b.staple
                    }
                  }
                }
              }
            }
          })
        })
      }
      const pagingList1: any = ref(pagingList)
      const machineUnit = ref(0)
      //色号
      const colornumberlist = ref([]) as any
      const colornumber = ref('')
      //色称
      const colornamelist = ref([]) as any
      const colorname = ref('')
      //等级
      const dengjilist = ref([]) as any
      const dengji = ref('')
      const getcolornumber = (val: any) => {
        if (val == '色号') {
          post({
            url: '/product/color/getColorPage',
            data: {
              deleteState: 0,
              page: 1,
              size: 30,
              obsoleteState: 0,
            },
          }).then(({ data, code }: any) => {
            if (code === 200) {
              // (data as string[]).splice(0, 0, "全部");
              colornumberlist.value = data.list
              //sessionStorage.setItem("色号",JSON.stringify(data))
              //sessionStorage.setItem("物料名称",JSON.stringify(wuliaoname.value))
            } else {
              Message.error({
                content: '查询失败！',
                duration: 5000,
              })
            }
          })
        }
        //         else if(val=="色称"){
        //    post({
        //         url: "/product/color/getFieldValue",
        //         data: {colorName:""}
        //     }).then(({ data, code }: any) => {
        //         if (code === 200) {
        //             console.log(data);
        //            colornamelist.value=data
        //         } else {
        //             Message.error({
        //                 content: "查询失败！",
        //                 duration: 5000,
        //             });
        //         }
        //     });
        //         }
        else if (val == '等级') {
          post({
            url: '/product/RawmaterialLevel/getFieldValue',
            data: { levelName: '' },
          }).then(({ data, code }: any) => {
            if (code === 200) {
              // (data as string[]).splice(0, 0, "全部");
              dengjilist.value = data
              //sessionStorage.setItem("色号",JSON.stringify(data))
              //sessionStorage.setItem("物料名称",JSON.stringify(wuliaoname.value))
            } else {
              Message.error({
                content: '查询失败！',
                duration: 5000,
              })
            }
          })
        }
      }
      const isBan = (value: any) => {
        //sessionStorage.setItem("启用与禁用6666",JSON.stringify(value))
        // pageData.spRowList.map((o:any)=>{
        //     if(o.id==value.record.id){
        //         o.isban=value.isban
        //     }
        // })
      }
      const fuzhixiala = (val: any) => {
        //sessionStorage.setItem("色号色称等级",JSON.stringify(val))
        if (
          val.record.colorAccording != null ||
          val.record.colorAccording != undefined ||
          val.record.colorAccording != ''
        ) {
          val.record.colorAccording = val.item.colorName
        }
      }

      //复制工艺，颜色改编号，新增一条数据
      const iscopy = (val: any) => {
        wdbiaoji.value = 0

        //复制工艺准备的数组
        var shuzu = [
          'A',
          'B',
          'C',
          'D',
          'E',
          'F',
          'G',
          'H',
          'I',
          'J',
          'K',
          'L',
          'M',
          'N',
          'O',
          'P',
          'Q',
          'R',
          'S',
          'T',
          'U',
          'V',
          'W',
          'X',
          'Y',
          'Z',
        ]
        //复制颜色准备的数组
        var shuzu2 = [] as any
        for (var i = 1; i <= 100; i++) {
          shuzu2[i - 1] = String(i)
        }

        var shu1 = gridOption.value.getSelectedRows()[0]['greyCode'].length - 1
        var mowei = gridOption.value.getSelectedRows()[0]['greyCode'].charAt(shu1)
        var lizi = gridOption.value.getSelectedRows()[0]['greyCode'].includes('-')

        var duixiang = gridOption.value.getSelectedRows()[0]['greyCode']
        var ceshide = duixiang.substring(0, duixiang.indexOf('-'))
        if (val == '工艺') {
          if (lizi == false) {
            shuzu.map((o: any, index: any) => {
              if (mowei != o && index == 0) {
                gridOption.value.getSelectedRows()[0]['greyCode'] =
                  gridOption.value.getSelectedRows()[0]['greyCode'] + shuzu[0]
                return
              } else if (mowei == o) {
                gridOption.value.getSelectedRows()[0]['greyCode'] =
                  gridOption.value.getSelectedRows()[0]['greyCode'].substr(0, shu1) +
                  shuzu[index + 1]
                return
              }
            })
          } else if (lizi == true) {
            var anli = duixiang.substr(0, duixiang.indexOf('-'))
            shuzu.map((o: any, index: any) => {
              if (anli.charAt(anli.length - 1) != o && index == 0) {
                gridOption.value.getSelectedRows()[0]['greyCode'] =
                  duixiang.substr(0, duixiang.indexOf('-') - 1) +
                  'A-' +
                  duixiang.substr(duixiang.indexOf('-') + 1, duixiang.length)

                return
              } else if (anli.charAt(anli.length - 1) == o) {
                gridOption.value.getSelectedRows()[0]['greyCode'] =
                  duixiang.substr(0, duixiang.indexOf('-') - 1) +
                  shuzu[index + 1] +
                  '-' +
                  duixiang.substr(duixiang.indexOf('-') + 1, duixiang.length)

                return
              }
            })
          }
        } else if (val == '颜色') {
          var houliangwei = gridOption.value.getSelectedRows()[0]['greyCode']
          if (houliangwei.includes('-') == true) {
            var a = gridOption.value.getSelectedRows()[0]['greyCode'].indexOf('-') + 1
            var houmian = gridOption.value.getSelectedRows()[0]['greyCode'].substr(a, shu1 + 1) //获取-后面的数
            shuzu2.map((o: any, index: any) => {
              if (houmian == o) {
                gridOption.value.getSelectedRows()[0]['greyCode'] =
                  gridOption.value.getSelectedRows()[0]['greyCode'].substr(0, a - 1) +
                  '-' +
                  shuzu2[index + 1]
              }
            })
          } else if (houliangwei.includes('-') == false) {
            gridOption.value.getSelectedRows()[0]['greyCode'] =
              gridOption.value.getSelectedRows()[0]['greyCode'] + '-' + shuzu2[0]
          }
        } else if (val == '工艺颜色') {
          var houliangwei = gridOption.value.getSelectedRows()[0]['greyCode']
          if (houliangwei.includes('-') == true) {
            var anli = duixiang.substr(0, duixiang.indexOf('-') - 1)
            var wuyu = duixiang.substr(0, duixiang.indexOf('-'))
            var qianmianmo = wuyu.charAt(anli.length) //-前面的字符
            shuzu.map((o: any, index: any) => {
              if (qianmianmo != o && index == 0) {
                gridOption.value.getSelectedRows()[0]['greyCode'] = anli + shuzu[0] + '-'
              } else if (qianmianmo == o) {
                gridOption.value.getSelectedRows()[0]['greyCode'] = anli + shuzu[index + 1] + '-'
              }
            })

            var houmiande = duixiang.substr(duixiang.indexOf('-') + 1, duixiang.length)

            shuzu2.map((o: any, index: any) => {
              if (houmiande == o) {
                gridOption.value.getSelectedRows()[0]['greyCode'] =
                  gridOption.value.getSelectedRows()[0]['greyCode'] + shuzu2[index + 1]
              }
            })
          } else if (houliangwei.includes('-') == false) {
            shuzu.map((o: any, index: any) => {
              if (mowei != o && index == 0) {
                gridOption.value.getSelectedRows()[0]['greyCode'] =
                  gridOption.value.getSelectedRows()[0]['greyCode'].substr(0, shu1) + 'A-1'
                return
              } else if (mowei == o) {
                gridOption.value.getSelectedRows()[0]['greyCode'] =
                  gridOption.value.getSelectedRows()[0]['greyCode'].substr(0, shu1) +
                  shuzu[index + 1] +
                  '-1'
                return
              }
            })
          }
        }
        jinxingfuzhi()
      }
      const panduanfuzhi = () => {
        post({
          url: 'product/Rawmaterial/getGreyDrop',
          data: { greyCode: '' },
        }).then(({ data, code }: any) => {
          if (code === 200) {
            // (data as string[]).splice(0, 0, "全部");
            //sessionStorage.setItem("所有坯布编号",JSON.stringify(data))

            data.map((o: any, index: any) => {
              if ((o.greyCode = gridOption.value.getSelectedRows()[0]['greyCode'])) {
                pdbiaoji.value = 1
                //doRefresh()
                return
              } else if (
                index == 0 &&
                o.greyCode != gridOption.value.getSelectedRows()[0]['greyCode']
              ) {
              }
            })
          } else {
            Message.error({
              content: '查询失败！',
              duration: 5000,
            })
          }
        })
      }

      const jinxingfuzhi = () => {
        getsanbianhao()
        post({
          url: 'product/pdGreyInformation/select',
          data: {
            id:
              shenhebiaoji.value == 1
                ? table1Ref.value.getSelectedRows()[0].id
                : table2Ref.value.getSelectedRows()[0].id,
          },
        }).then(({ data, code }: any) => {
          if (code === 200) {
            console.log(data)

            caikoupaizhen.value = data.cuttingMouthNeedleGrey
            if (caikoupaizhen.value.length != 0) {
              caikoupaizhen.value[0]['id'] = ''
            }

            //原来复制的数据
            // data.greyInformation.greyCode = gridOption.value.getSelectedRows()[0]['greyCode']
            // data.greyInformation.id = ""
            // var caikoupaizhen = [] as any;
            // data.cuttingMouthNeedleGrey.map((a: any) => {
            //     var zz = {
            //         arrangement: a.arrangement,
            //         pinHeader: a.pinHeader
            //     }
            //     caikoupaizhen.push(zz)
            // })
            // data.organizationPinSons.map((o: any) => {
            //     o.id = ""
            // })
            // data.yarnStructures.map((o: any) => {
            //     o.id = ""
            // })
            // let greyInformations=dataForm
            //   greyInformations['machineUnit'] = machineUnit.value
            //             greyInformations['theoryPrice'] = theoryPrice.value
            // //准备复制的数据
            // var obj = {
            //     arrangementTriangle: {
            //         atCode: data.arrangementTriangleGreys.atCode,
            //         atName: data.arrangementTriangleGreys.atName,
            //         info: data.arrangementTriangleGreys.info,
            //         remark: data.arrangementTriangleGreys.remark
            //     },
            //     atOther: data.atOther,
            //     machineUnit: data.greyInformation.machineUnit,
            //     commodityGreyList: data.commodities,
            //     cuttingMouthNeedleGrey: { pinHeader: "", arrangement: "" },
            //     greyInformations: greyInformations,
            //     organizationPinSon: { organizationName: "", list: data.organizationPinSons },
            //     yarnStructure: data.yarnStructures
            // }
            let data1 = {}
            data1['psj'] = {
              atName: sjdata.atName,
              atCode: sjdata.atCode,
              remark: sjdata.atName,
              info: sjdata.sj,
            }

            data1['ckpz'] = ckpzobj
            data1['zzpz'] = zzpzdata.value
            data1['yl'] = ylTableList.value
            data1['sp'] = ''
            // 拼接额外信息
            let ewsjArr: any[] = []
            ewsj.value.forEach((o: any) => {
              ewsjArr = ewsjArr.concat(...o)
            })
            //新加 整合新增接口 排三角
            let arrangementTriangle = {}
            if (sjdata.sj.length > 0) {
              arrangementTriangle = {
                atName: sjdata.atName,
                atCode: sjdata.atCode,
                remark: sjdata.atName,
                info: sjdata.sj,
              }
            }
            let organizationPinSon = {}
            if (data1['zzpz'] != null) {
              let zzpzOb = zzpzListSelect.value.filter((item: any) => item.id == zzpzid.value)[0]
              organizationPinSon = {
                organizationName: zzpzOb == undefined ? '' : zzpzOb.organizationName,
                list: data1['zzpz'],
              }
            }
            //循环用户选中的商品 取id
            let commodityGreyList: any = []
            pageData.spRowList.forEach(function (o: any) {
              commodityGreyList.push(o['id'])
            })
            //原料列表、
            let yarnStructure = ylTableList.value
            let greyInformations = dataForm
            ckpzobj.id = undefined
            // greyInformations['machineUnit'] = machineUnit.value
            greyInformations['theoryPrice'] = theoryPrice.value
            greyInformations['crossMemo'] = crossMemo.value
            if (arrangementTriangle['info'] != null && arrangementTriangle['info'] != undefined) {
              arrangementTriangle['info'].map((o: any) => {
                o.typeData.map((a: any) => {
                  a.needleList.map((b: any) => {
                    b.circulationNum = xuanhuancihu.value
                    b.realOpenNum = shikaishu.value
                  })
                })
              })
            }

            organizationPinSon['list'].map((o: any) => {
              o.id = ''
            })
            yarnStructure.map((o: any) => {
              o.id = ''
            })
            greyInformations['id'] = ''
            if (shenhebiaoji.value == 1) {
              //未审核复制
              // post({
              //   url: 'product/pdGreyInformation/getPbbh',
              //   data: {
              //     processType: dataForm.processType,
              //     gncode: gongnengbianhao.value,
              //     szcode: shazhibianhao.value,
              //     blcode: buleibianhao.value,
              //     greyCode: gridOption.value.getSelectedRows()[0]['greyCode'],
              //     fromGreyCode: gridOption.value.getSelectedRows()[0]['fromGreyCode'],
              //     copyType: fuzhixinzengindex.value,
              //   },
              // }).then(({ code, data }) => {
              //   if (code === 200) {

              //   }
              // })
              greyInformations['greyCode'] = dataForm.greyCode
              var obj: any = {
                arrangementTriangle: arrangementTriangle,
                atOther: psList.value,
                machineUnit: machineUnit.value,
                commodityGreyList: commodityGreyList,
                //   cuttingMouthNeedleGrey: { pinHeader: "", arrangement: "" },
                cuttingMouthNeedleGrey: caikoupaizhen.value[0],
                greyInformations: greyInformations,
                // organizationPinSon: { organizationName: "", list: data.organizationPinSons },
                organizationPinSon: organizationPinSon,
                yarnStructure: yarnStructure,
              }
              obj.arrangementTriangle.loopList = settingLoopData.value
              startfuzhi(obj)
            } else {
              //已审核复制
              // post({
              //   url: 'product/pdGreyInformation/getPbbh',
              //   data: {
              //     processType: dataForm.processType,
              //     gncode: gongnengbianhao.value,
              //     szcode: shazhibianhao.value,
              //     blcode: buleibianhao.value,
              //     greyCode: gridOption2.value.getSelectedRows()[0]['greyCode'],
              //     fromGreyCode: gridOption2.value.getSelectedRows()[0]['fromGreyCode'],
              //     copyType: fuzhixinzengindex.value,
              //   },
              // }).then(({ message, code, data }) => {
              //   if (code === 200) {

              //   } else {
              //     Message.error({
              //       content: message,
              //       duration: 5000,
              //     })
              //     pageData.showAdd2 = false
              //   }
              // })
              greyInformations['greyCode'] = dataForm.greyCode
              var obj: any = {
                arrangementTriangle: arrangementTriangle,
                atOther: psList.value,
                machineUnit: machineUnit.value,
                commodityGreyList: commodityGreyList,
                cuttingMouthNeedleGrey: caikoupaizhen.value[0],
                greyInformations: greyInformations,
                // organizationPinSon: { organizationName: "", list: data.organizationPinSons },
                organizationPinSon: organizationPinSon,
                yarnStructure: yarnStructure,
              }
              obj.arrangementTriangle.loopList = settingLoopData.value
              startfuzhi(obj)
            }
          } else {
            Message.error({
              content: '查询失败！',
              duration: 5000,
            })
          }
        })
        xhCol.value = []
        for (var i = 0; i <= numb.col; i++) {
          xhCol.value.push({ val: i })
        }
      }

      //开始复制
      const startfuzhi = (val: any) => {
        post({
          url: '/product/pdGreyInformation/insertCopy',
          data: val,
        })
          .then((res: any) => {
            if (res.code === 200) {
              Message.success({
                content: '复制成功',
                duration: 5000,
              })
              //  pageData.showAdd2 = false
              doRefresh()
              pageData.pageLoading = false
              pageData.showAdd2 = false
            } else {
              Message.error({
                content: res.message,
                duration: 5000,
              })
            }
          })
          .finally(() => {
            doRefresh()
          })
      }
      const pdbiaoji = ref(0)
      //根据账号判断是否为本集团
      const shifoubenjituan = () => {
        get({
          url: '/admin/acl/user/getMemberIdByJwtToken',
          data: {},
        })
          .then((res: any) => {
            if (typeof res == 'string') {
              Message.error({
                content: '返回异常',
                duration: 5000,
              })
            }
            if (res.code === 200) {
              dataForm.processType = res.data.data.judgeGroup
              shifouxiugaibianhao.value = res.data.data.judgeGroup
            } else {
              Message.error({
                content: res.message,
                duration: 5000,
              })
            }
          })
          .finally(() => {})
      }
      //获取纱支比例
      const shabili = () => {
        post({
          url: '/product/YarnCountRatio/getPage',
          data: {
            page: page.value,
            size: size.value,
            deleteState: '0',
          },
        })
          .then(({ data, code }: any) => {
            if (code === 200) {
              shabilist.value = data.list
            }
          })
          .catch(console.log)
          .finally(() => {
            pageData.pageLoading = false
          })
      }
      const id = ref(null)
      const shabilist = ref([])
      const isshow = ref(true)
      const theoryPrice = ref(0)
      const huixianxunhuan = () => {
        let maxColNumber = 0
        sjdata.sj[0].typeData[0].needleList.forEach((o: any) => {
          if (o.way > maxColNumber) {
            maxColNumber = parseInt(o.way)
          }
        })
        // let n = maxColNumber - numb.col
        let n = maxColNumber - shikaishu.value
        if (n < 0) {
          for (let i = n; i < 0; i++) {
            sjdata.sj.forEach((o: any) => {
              o.typeData.forEach((o1: any, id: number) => {
                o1.needleList.push({
                  way: maxColNumber + Math.abs(n - i) + 1,
                  needle: '',
                })
              })
            })

            for (let k = 0; k < psList.value.length; k++) {
              // for (let j = 0; j < psList.value[k].length; j++) {
              psList.value[k].push({ val: '' })
              // }
            }
          }
        } else if (n > 0) {
          for (let i = 0; i < n; i++) {
            sjdata.sj.forEach((o: any, i: number) => {
              o.typeData.forEach((o1: any) => {
                o1.needleList.pop()
              })
            })
            for (let k = 0; k < psList.value.length; k++) {
              // for (let j = 0; j < psList.value[k].length; j++) {
              psList.value[k].pop()
              // }
            }
          }
        } else {
          return
        }
        xhCol.value = []
        // for (let i = 0; i <= numb.col; i++) {
        //     xhCol.value.push({ val: i })
        // }
        for (let i = 0; i <= numb.col; i++) {
          xhCol.value.push({ val: i })
        }
      }

      const wdfz = () => {
        wdbiaoji.value++
        if (wdbiaoji.value % 2 != 0) {
        }
      }
      const setSPData = () => {
        var aa = [] as any
        var old = psList.value
        for (var i = 0; i < ylTableList.value.length + 1; i++) {
          var shuzu = [] as any
          for (var j = 0; j <= 1 + xhCol.value.length; j++) {
            if (i > 0 && j == 1) {
              var obj2 = {
                val: ylTableList.value[i - 1].yarnSource,
                text: ylTableList.value[i - 1].staple,
              }
              shuzu.push(obj2)
            }
            if (i == 0 && j == 2) {
              var obj = { val: '排纱' }
              shuzu.push(obj)
            }
            if (i != 0 && j == 0) {
              var obj = { val: '纱长(cm)' }
              shuzu.push(obj)
            }
            if (i == 0 && j != 2) {
              var obj3 = { val: '' }
              shuzu.push(obj3)
            }
            if (i > 0 && j > 1) {
              var obj3 = { val: '' }
              shuzu.push(obj3)
            }
          }

          aa.push(shuzu)
        }
        psList.value = aa
        psList.value.map((o: any, index1: any) => {
          o.map((a: any, index2: any) => {
            old.map((m: any, index3: any) => {
              m.map((n: any, index4: any) => {
                if (index1 == index3) {
                  if (index2 == index4) {
                    a.val = n.val
                  }
                }
              })
            })
          })
        })
      }
      //重置排纱和序号列
      const shuaxinpaisha = () => {
        // psList.value=[];
        var aa = [] as any
        var old = psList.value
        for (var i = 0; i < ylTableList.value.length + 1; i++) {
          var shuzu = [] as any
          for (var j = 0; j <= 2 + numb.col; j++) {
            if (i > 0 && j == 1) {
              var obj2 = {
                val: ylTableList.value[i - 1].yarnSource,
                text: ylTableList.value[i - 1].staple,
              }
              shuzu.push(obj2)
            }
            if (i == 0 && j == 2) {
              var obj = { val: '排纱' }
              shuzu.push(obj)
            }
            if (i != 0 && j == 0) {
              var obj = { val: '纱长(cm)' }
              shuzu.push(obj)
            }
            if (i == 0 && j != 2) {
              var obj3 = { val: '' }
              shuzu.push(obj3)
            }
            if (i > 0 && j > 1) {
              var obj3 = { val: '' }
              shuzu.push(obj3)
            }
          }

          aa.push(shuzu)
        }
        psList.value = aa
        psList.value.map((o: any, index1: any) => {
          o.map((a: any, index2: any) => {
            old.map((m: any, index3: any) => {
              m.map((n: any, index4: any) => {
                if (index1 == index3) {
                  if (index2 == index4) {
                    a.val = n.val
                  }
                }
              })
            })
          })
        })
        //序号重写
        var xhshuzu: any = []
        for (var i = 0; i <= numb.col; i++) {
          xhshuzu.push({ val: i })
        }
        xhCol.value = xhshuzu
        //重写上下排针
        if (pageData.sideTitle == '修改坯布') {
          var shangpanlist = [] as any
          var xiapanlist = [] as any
          var oldpaisha = [] as any //拿到旧的排纱数据
          oldpaisha = sjdata.sj

          if (xuanzepaisanjiaolist.value.length > 0) {
            oldpaisha = xuanzepaisanjiaolist.value
          }

          let panduanziduan = ''
          if (huancunpanduanziduan.value == '') {
            oldpaisha.map((o: any) => {
              panduanziduan = panduanziduan + o.type
            })
            huancunpanduanziduan.value = panduanziduan
          } else {
            panduanziduan = huancunpanduanziduan.value
          }
          for (var i = 0; i < numb.row[0]; i++) {
            var a = { serialNumber: i + 1, needleName: '', needleList: [{ needle: '', way: 1 }] }
            shangpanlist.push(a)
          }
          for (var i = 0; i < numb.row[1]; i++) {
            var a = { serialNumber: i + 1, needleName: '', needleList: [{ needle: '', way: 1 }] }
            xiapanlist.push(a)
          }
          sjdata.sj = [
            {
              type: '上盘',
              typeData: shangpanlist,
              show: panduanziduan.includes('上盘') == true ? true : false,
            },
            {
              type: '下盘',
              typeData: xiapanlist,
              show: panduanziduan.includes('下盘') == true ? true : false,
            },
          ]

          var jj = [] as any
          sjdata.sj.map((o: any) => {
            if (o.show == true) {
              jj.push(o)
            }
          })
          sjdata.sj = jj
          for (var i = 0; i < numb.col - 1; i++) {
            //sjdata.sj[0].typeData[0].needleList.push({needle:'',way:i+2})
            sjdata.sj.map((o: any) => {
              o.typeData.map((a: any) => {
                a.needleList.push({ needle: '', way: i + 2 })
              })
            })
            //根据选择的排三角设置排纱
            paishabiaoji.value++
          }
          oldpaisha.map((c: any) => {
            c.typeData.map((d: any) => {
              d.needleList.map((e: any) => {
                sjdata.sj.map((o: any) => {
                  if (o.type == c.type) {
                    o.typeData.map((a: any) => {
                      if (a.serialNumber == d.serialNumber) {
                        a.needleName = d.needleName
                        a.needleList.map((q: any) => {
                          if (q.way == e.way) {
                            if (q.needle == '' || q.needle == undefined) {
                              q.needle = e.needle
                            }
                          }
                        })
                      }
                    })
                  }
                })
              })
            })
          })

          if (xuanzepaisanjiaolist.value.length > 0) {
            sjdata.sj = xuanzepaisanjiaolist.value
            //      xuanzepaisanjiaolist.value.map((c:any)=>{
            //             c.typeData.map((d:any)=>{
            //                 d.needleList.map((e:any)=>{
            //                    sjdata.sj.map((o:any)=>{
            //                     if(o.type==c.type){
            //                       //o.show=true
            //                         o.typeData.map((a:any)=>{

            //        if(a.serialNumber==d.serialNumber){
            //          a.needleName=d.needleName
            //            a.needleList.map((q:any)=>{

            //             if(q.way==e.way){

            //             q.needle=e.needle

            //           }
            //        })
            //          }

            //     })
            //                     }

            //   })
            //                 })
            //             })
            //         })

            sjdata.sj.map((o: any) => {
              o.typeData.map((a: any) => {
                var changdu = a.needleList.length
                if (numb.col - changdu >= 0) {
                  for (var i = 1; i <= numb.col - changdu; i++) {
                    a.needleList.push({ needle: '', way: i + changdu })
                  }
                } else {
                  var cha = changdu - numb.col
                  a.needleList.splice(numb.col, cha)
                }
              })
            })
          } else {
            sjdata.sj = oldpaisha
            sjdata.sj.map((o: any) => {
              o.typeData.map((a: any) => {
                var changdu = a.needleList.length
                if (numb.col - changdu >= 0) {
                  for (var i = 1; i <= numb.col - changdu; i++) {
                    a.needleList.push({ needle: '', way: i + changdu })
                  }
                } else {
                  var cha = changdu - numb.col
                  a.needleList.splice(numb.col, cha)
                }
              })
            })
          }
        } else if (pageData.sideTitle == '新增坯布') {
          var laopai = sjdata.sj
          // numb.row = [2, 4]
          if (sjdata.sj == undefined || sjdata.sj == null) {
            sjdata.sj = []
          }
          console.log(xuanzepaisanjiaolist.value)
          if (xuanzepaisanjiaolist.value.length == 0) {
            let list = []
            for (let i = 0; i < numb.col; i++) {
              let ob: any = {}
              ob['needle'] = ''
              ob['way'] = i + 1
              list.push(ob)
            }

            if (dataForm.machineType == '单面机') {
              sjdata.sj = [
                {
                  type: '下盘',
                  typeData: [
                    {
                      serialNumber: 1,
                      needleName: '',
                      needleList: JSON.parse(JSON.stringify(list)),
                    },
                    {
                      serialNumber: 2,
                      needleName: '',
                      needleList: JSON.parse(JSON.stringify(list)),
                    },
                    {
                      serialNumber: 3,
                      needleName: '',
                      needleList: JSON.parse(JSON.stringify(list)),
                    },
                    {
                      serialNumber: 4,
                      needleName: '',
                      needleList: JSON.parse(JSON.stringify(list)),
                    },
                  ],
                },
              ]
            } else {
              sjdata.sj = [
                {
                  type: '上盘',
                  typeData: [
                    {
                      serialNumber: 1,
                      needleName: '',
                      needleList: JSON.parse(JSON.stringify(list)),
                    },
                    {
                      serialNumber: 2,
                      needleName: '',
                      needleList: JSON.parse(JSON.stringify(list)),
                    },
                  ],
                },
                {
                  type: '下盘',
                  typeData: [
                    {
                      serialNumber: 1,
                      needleName: '',
                      needleList: JSON.parse(JSON.stringify(list)),
                    },
                    {
                      serialNumber: 2,
                      needleName: '',
                      needleList: JSON.parse(JSON.stringify(list)),
                    },
                    {
                      serialNumber: 3,
                      needleName: '',
                      needleList: JSON.parse(JSON.stringify(list)),
                    },
                    {
                      serialNumber: 4,
                      needleName: '',
                      needleList: JSON.parse(JSON.stringify(list)),
                    },
                  ],
                },
              ]
            }
          } else {
            sjdata.sj = xuanzepaisanjiaolist.value
            //如果选择了三角，就拿三角数据
            //       var shangpanlist=[] as any;
            //         var xiapanlist=[] as any;
            //              var oldpaisha=[] as any;//拿到旧的排纱数据
            //              oldpaisha= sjdata.sj
            //              if(xuanzepaisanjiaolist.value.length!=0){

            //                 oldpaisha=xuanzepaisanjiaolist.value
            //              }

            //      let panduanziduan=""
            //      if(huancunpanduanziduan.value==""){
            //          oldpaisha.map((o:any)=>{
            //         panduanziduan=panduanziduan+o.type

            //      })
            //      huancunpanduanziduan.value=panduanziduan
            //      }else{
            //            panduanziduan=huancunpanduanziduan.value
            //      }
            //       xuanzepaisanjiaolist.value.map((o:any,index:any)=>{
            //            if(o.type=="上盘"){
            //             numb.row[0]=o.typeData.length
            //            }
            //            if(o.type=="下盘"){
            //              numb.row[1]=o.typeData.length
            //            }
            //         })
            //            for(var i=0;i<numb.row[0];i++){
            //         var a={serialNumber:i+1,needleName:"",needleList:[{needle:"",way:1}]}
            //          shangpanlist.push(a)
            //       }
            //      for(var i=0;i<numb.row[1];i++){
            //         var a={serialNumber:i+1,needleName:"",needleList:[{needle:"",way:1}]}
            //          xiapanlist.push(a)
            //       }

            //         sjdata.sj = [
            //     {
            //         type: '上盘',
            //         typeData: shangpanlist,
            //         show:panduanziduan.includes('上盘')==true?true:false

            //     },
            //     {
            //         "type":'下盘',
            //         "typeData":xiapanlist,
            //          show:panduanziduan.includes('下盘')==true?true:false
            //     }

            // ]
            // }

            //     for(var i=0;i<shikaishu.value-1;i++){
            //   //sjdata.sj[0].typeData[0].needleList.push({needle:'',way:i+2})
            //   sjdata.sj.map((o:any)=>{
            //     o.typeData.map((a:any)=>{
            //         a.needleList.push({needle:'',way:i+2})

            //     })
            //   })
            //      //根据选择的排三角设置排纱
            //      if(xuanzepaisanjiaolist.value.length>0){
            //      xuanzepaisanjiaolist.value.map((c:any)=>{
            //             c.typeData.map((d:any)=>{
            //                 d.needleList.map((e:any)=>{
            //                    sjdata.sj.map((o:any)=>{
            //                     if(o.type==c.type){
            //                         o.typeData.map((a:any)=>{

            //        if(a.serialNumber==d.serialNumber){
            //          a.needleName=d.needleName
            //            a.needleList.map((q:any)=>{

            //             if(q.way==e.way){
            //                  if(q.needle==""){
            //             q.needle=e.needle
            //                  }
            //           }
            //        })
            //          }

            //     })
            //                     }

            //   })
            //                 })
            //             })
            //         })
            //      }

            sjdata.sj.map((o: any) => {
              o.typeData.map((a: any) => {
                var changdu = a.needleList.length
                if (numb.col - changdu >= 0) {
                  for (var i = 1; i <= numb.col - changdu; i++) {
                    a.needleList.push({ needle: '', way: i + changdu })
                  }
                } else {
                  var cha = changdu - numb.col
                  a.needleList.splice(numb.col, cha)
                }
              })
            })
          }
        } else if (pageData.sideTitle == '复制新增') {
          var shangpanlist = [] as any
          var xiapanlist = [] as any
          var oldpaisha = [] as any //拿到旧的排纱数据
          oldpaisha = sjdata.sj

          if (xuanzepaisanjiaolist.value.length > 0) {
            oldpaisha = xuanzepaisanjiaolist.value
          }

          let panduanziduan = ''
          if (huancunpanduanziduan.value == '') {
            oldpaisha.map((o: any) => {
              panduanziduan = panduanziduan + o.type
            })
            huancunpanduanziduan.value = panduanziduan
          } else {
            panduanziduan = huancunpanduanziduan.value
          }
          for (var i = 0; i < numb.row[0]; i++) {
            var a = { serialNumber: i + 1, needleName: '', needleList: [{ needle: '', way: 1 }] }
            shangpanlist.push(a)
          }
          for (var i = 0; i < numb.row[1]; i++) {
            var a = { serialNumber: i + 1, needleName: '', needleList: [{ needle: '', way: 1 }] }
            xiapanlist.push(a)
          }
          sjdata.sj = [
            {
              type: '上盘',
              typeData: shangpanlist,
              show: panduanziduan.includes('上盘') == true ? true : false,
            },
            {
              type: '下盘',
              typeData: xiapanlist,
              show: panduanziduan.includes('下盘') == true ? true : false,
            },
          ]

          var jj = [] as any
          sjdata.sj.map((o: any) => {
            if (o.show == true) {
              jj.push(o)
            }
          })
          sjdata.sj = jj
          for (var i = 0; i < numb.col - 1; i++) {
            //sjdata.sj[0].typeData[0].needleList.push({needle:'',way:i+2})
            sjdata.sj.map((o: any) => {
              o.typeData.map((a: any) => {
                a.needleList.push({ needle: '', way: i + 2 })
              })
            })
            //根据选择的排三角设置排纱
            paishabiaoji.value++
          }
          oldpaisha.map((c: any) => {
            c.typeData.map((d: any) => {
              d.needleList.map((e: any) => {
                sjdata.sj.map((o: any) => {
                  if (o.type == c.type) {
                    o.typeData.map((a: any) => {
                      if (a.serialNumber == d.serialNumber) {
                        a.needleName = d.needleName
                        a.needleList.map((q: any) => {
                          if (q.way == e.way) {
                            if (q.needle == '' || q.needle == undefined) {
                              q.needle = e.needle
                            }
                          }
                        })
                      }
                    })
                  }
                })
              })
            })
          })

          if (xuanzepaisanjiaolist.value.length > 0) {
            sjdata.sj = xuanzepaisanjiaolist.value
            //      xuanzepaisanjiaolist.value.map((c:any)=>{
            //             c.typeData.map((d:any)=>{
            //                 d.needleList.map((e:any)=>{
            //                    sjdata.sj.map((o:any)=>{
            //                     if(o.type==c.type){
            //                       //o.show=true
            //                         o.typeData.map((a:any)=>{

            //        if(a.serialNumber==d.serialNumber){
            //          a.needleName=d.needleName
            //            a.needleList.map((q:any)=>{

            //             if(q.way==e.way){

            //             q.needle=e.needle

            //           }
            //        })
            //          }

            //     })
            //                     }

            //   })
            //                 })
            //             })
            //         })

            sjdata.sj.map((o: any) => {
              o.typeData.map((a: any) => {
                var changdu = a.needleList.length
                if (numb.col - changdu >= 0) {
                  for (var i = 1; i <= numb.col - changdu; i++) {
                    a.needleList.push({ needle: '', way: i + changdu })
                  }
                } else {
                  var cha = changdu - numb.col
                  a.needleList.splice(numb.col, cha)
                }
              })
            })
          } else {
            sjdata.sj = oldpaisha
            sjdata.sj.map((o: any) => {
              o.typeData.map((a: any) => {
                var changdu = a.needleList.length
                if (numb.col - changdu >= 0) {
                  for (var i = 1; i <= numb.col - changdu; i++) {
                    a.needleList.push({ needle: '', way: i + changdu })
                  }
                } else {
                  var cha = changdu - numb.col
                  a.needleList.splice(numb.col, cha)
                }
              })
            })
          }
        }
        if (paishabiaoji.value >= 1) {
          xuanzepaisanjiaolist.value = sjdata.sj
        }
        paishabiaoji.value++
      }

      const wdbiaoji = ref(0)
      const xuanranpaisha = () => {
        addFlag.value = 1
        shuaxinpaisha()
      }
      const yichu = () => {
        wdbiaoji.value = 0
      }
      const fuzhixinzeng = (val: any) => {
        if (shenhebiaoji.value == 1) {
          if (table1Ref.value.getSelectedRows().length === 0) {
            Message.error('请先勾选')
            return
          }
          if (table1Ref.value.getSelectedRows().length > 1) {
            Message.error('只能勾选一条数据')
            return
          }
          if (val == '工艺') {
            fuzhixinzengindex.value = 0
          } else if (val == '颜色') {
            fuzhixinzengindex.value = 1
          } else {
            fuzhixinzengindex.value = 2
          }
        } else {
          if (table2Ref.value.getSelectedRows().length === 0) {
            Message.error('请先勾选')
            return
          }
          if (table2Ref.value.getSelectedRows().length > 1) {
            Message.error('只能勾选一条数据')
            return
          }
          if (val == '工艺') {
            fuzhixinzengindex.value = 0
          } else if (val == '颜色') {
            fuzhixinzengindex.value = 1
          } else {
            fuzhixinzengindex.value = 2
          }
        }
        psjpb.value = null
        psList.value = []
        ylTableList.value = []
        zzpzSelect('')
        id.value =
          shenhebiaoji.value == 1
            ? table1Ref.value.getSelectedRows()[0]['id']
            : table2Ref.value.getSelectedRows()[0]['id']
        // -----------
        pageData.ylCfIdList = []
        selectedRowKeys.value = []

        pageData.isDetails = false

        pageData.zhong = ''
        pageData.yin = ''
        const idToData = allDataList.filter(
          (item) =>
            item.id ==
            (shenhebiaoji.value == 1
              ? table1Ref.value.getSelectedRows()[0]['id']
              : table2Ref.value.getSelectedRows()[0]['id'])
        )

        //判断本集团外加工
        post({
          url: '/product/pdGreyInformation/getState',
          data: {
            processType:
              shenhebiaoji.value == 1
                ? table1Ref.value.getSelectedRows()[0]['processType']
                : table2Ref.value.getSelectedRows()[0]['processType'],
          },
        }).then(({ code, message }: any) => {
          if (message === '0') {
            post({
              url: 'product/pdGreyInformation/select',
              data: {
                id:
                  shenhebiaoji.value == 1
                    ? table1Ref.value.getSelectedRows()[0]['id']
                    : table2Ref.value.getSelectedRows()[0]['id'],
              },
            }).then(({ code, data }) => {
              if (code === 200) {
                // 原料列表
                ylTableList.value = data.yarnStructures
                ylTableList.value.forEach(function (o: any) {
                  pageData.ylCfIdList.push(o['ylId'])
                })
                //tw加
                ylTableList.value.forEach((o: any) => {
                  var cha = o.actualYarn - o.yarnCountProportion
                  for (let item of shabilist.value) {
                    if (
                      cha >= Number(item['yarnCountMin']) &&
                      cha <= Number(item['yarnCountMax'])
                    ) {
                      o.jieguo = 1
                      break
                    } else {
                      o.jieguo = 2
                    }
                  }
                })
                // machineUnit.value = data.greyInformation.machineUnit
                dataForm.processType = data.greyInformation.processType
                if (
                  data.arrangementTriangleGreys['info'] != undefined &&
                  data.arrangementTriangleGreys['info'] != null
                ) {
                  data.arrangementTriangleGreys.info.map((o: any) => {
                    o.typeData.map((a: any) => {
                      a.needleList.map((b: any) => {
                        xuanhuancihu.value = b.circulationNum
                        shikaishu.value = b.realOpenNum
                      })
                    })
                  })
                } else {
                  xuanhuancihu.value = 1
                  shikaishu.value = 1
                }
                console.log(xuanhuancihu.value)
                console.log(shikaishu.value)
                //---------------
                // 组织排针 列数
                colNumber.value =
                  data.organizationPinSons.length == 0 ? 1 : data.organizationPinSons.length
                // 组织排针 数据
                zzpzdata.value =
                  data.organizationPinSons.length == 0
                    ? [
                        {
                          upBasin: '',
                          belowBasin: '',
                          id: '',
                          pdOrganizationPinId: '',
                        },
                      ]
                    : data.organizationPinSons
                // 裁口排针
                if (data.cuttingMouthNeedleGrey != null) {
                  let cuttingMouthNeedleGrey = data.cuttingMouthNeedleGrey
                  ckpzobj.id = cuttingMouthNeedleGrey.id
                  ckpzobj.pinHeader = cuttingMouthNeedleGrey.pinHeader
                  ckpzobj.arrangement = cuttingMouthNeedleGrey.arrangement
                }
                //tw加
                ckpzobj.pinHeader = data.cuttingMouthNeedleGrey[0].pinHeader
                ckpzobj.arrangement = data.cuttingMouthNeedleGrey[0].arrangement
                // 关联商品渲染
                pageData.spRowList = data.commodities
                // 排三角arrangementTriangleGreys
                sjdata.sj = data.arrangementTriangleGreys.info
                sjdata.atCode = data.arrangementTriangleGreys.atCode
                sjdata.atName = data.arrangementTriangleGreys.atName
                sjdata.remark = data.arrangementTriangleGreys.remark
                psList.value = data.atOther
              }
              if (sjdata.sj == undefined || sjdata.sj == null) {
                sjdata.sj = []
              }
              if (sjdata.sj.length == 0) {
                if (dataForm.machineType == '单面机') {
                  sjdata.sj = [
                    {
                      type: '下盘',
                      typeData: [
                        {
                          serialNumber: 1,
                          needleName: '',
                          needleList: [{ way: 1 }],
                        },
                        {
                          serialNumber: 2,
                          needleName: '',
                          needleList: [
                            {
                              needle: '',
                              way: 1,
                            },
                          ],
                        },
                        {
                          serialNumber: 3,
                          needleName: '',
                          needleList: [
                            {
                              needle: '',
                              way: 1,
                            },
                          ],
                        },
                        {
                          serialNumber: 4,
                          needleName: '',
                          needleList: [
                            {
                              needle: '',
                              way: 1,
                            },
                          ],
                        },
                      ],
                    },
                  ]
                } else {
                  sjdata.sj = [
                    {
                      type: '上盘',
                      typeData: [
                        {
                          serialNumber: 1,
                          needleName: '',
                          needleList: [
                            {
                              needle: '',
                              way: 1,
                            },
                          ],
                        },
                        {
                          serialNumber: 2,
                          needleName: '',
                          needleList: [
                            {
                              needle: '',
                              way: 1,
                            },
                          ],
                        },
                      ],
                    },
                    {
                      type: '下盘',
                      typeData: [
                        {
                          serialNumber: 1,
                          needleName: '',
                          needleList: [{ way: 1 }],
                        },
                        {
                          serialNumber: 2,
                          needleName: '',
                          needleList: [
                            {
                              needle: '',
                              way: 1,
                            },
                          ],
                        },
                        {
                          serialNumber: 3,
                          needleName: '',
                          needleList: [
                            {
                              needle: '',
                              way: 1,
                            },
                          ],
                        },
                        {
                          serialNumber: 4,
                          needleName: '',
                          needleList: [
                            {
                              needle: '',
                              way: 1,
                            },
                          ],
                        },
                      ],
                    },
                  ]
                }
              }
              if (sjdata.sj.length === 1) {
                dataForm.models = '1'
              } else {
                dataForm.models = '2'
              }
              numb.row = sjdata.sj.map((o: any) => {
                return o.typeData.length
              })
              //let maxColNumber = 0
              //tw改
              let maxColNumber = shikaishu.value

              //---
              sjdata.sj[0].typeData[0].needleList.forEach((o: any) => {
                if (o.way > maxColNumber) {
                  maxColNumber = parseInt(o.way)
                }
              })
              numb.col = maxColNumber

              shikaishu.value = maxColNumber

              xhCol.value = []
              // numb.col = shikaishu.value / xuanhuancihu.value

              if (data.arrangementTriangleGreys.loopList?.length > 0) {
                xhCol.value = [
                  {
                    val: 0,
                  },
                ]
                let onceCount = 0
                settingLoopData.value = data.arrangementTriangleGreys.loopList
                data.arrangementTriangleGreys.loopList.forEach((item: any) => {
                  for (let index = item.wayStart; index < item.wayEnd + 1; index++) {
                    xhCol.value.push({ val: index })

                    onceCount += item.loopCount
                  }
                })
                shikaishu.value = onceCount
              } else {
                xhCol.value = []
                for (let i = 0; i <= numb.col; i++) {
                  xhCol.value.push({ val: i })
                }
              }
              numb.col = xhCol.value.length - 1
            })
            if (idToData.length > 0) {
              for (let key in idToData[0]) {
                dataForm[key] = idToData[0][key]
              }
            }
            // dataForm.grayFabricName = idToData[0].grayFabricName
            nextTick(() => {
              dataForm.grayFabricName = idToData[0].grayFabricName
            })
            pageData.showAdd2 = true
            pageData.sideTitle = '复制新增'
            szSelect('')
            focusBl()
            focusGn()
            setTimeout(() => {
              codeGens(dataForm.grayFabricName)
            }, 500)
          } else {
            Message.error(message)
          }
        })

        ylId.value = ''

        //侧滑栏滑出滑入

        xhCol.value = []

        for (let i = 0; i <= numb.col; i++) {
          var obj = { val: i }
          xhCol.value.push(obj)
        }
        addFlag.value = -1
      }
      const fuzhixinzengindex = ref(0)
      const huoqufuzhishuju = () => {
        let data1 = {}
        data1['psj'] = {
          atName: sjdata.atName,
          atCode: sjdata.atCode,
          remark: sjdata.atName,
          info: sjdata.sj,
        }

        data1['ckpz'] = ckpzobj
        data1['zzpz'] = zzpzdata.value
        data1['yl'] = ylTableList.value
        data1['sp'] = ''
        // 拼接额外信息
        let ewsjArr: any[] = []
        ewsj.value.forEach((o: any) => {
          ewsjArr = ewsjArr.concat(...o)
        })
        //hcw 新加 整合新增接口 排三角
        let arrangementTriangle = {}
        if (sjdata.sj.length > 0) {
          arrangementTriangle = {
            atName: sjdata.atName,
            atCode: sjdata.atCode,
            remark: sjdata.atName,
            info: sjdata.sj,
          }
        }
        let organizationPinSon = {}
        if (data1['zzpz'] != null) {
          let zzpzOb = zzpzListSelect.value.filter((item: any) => item.id == zzpzid.value)[0]
          organizationPinSon = {
            organizationName: zzpzOb == undefined ? '' : zzpzOb.organizationName,
            list: data1['zzpz'],
          }
        }
        //循环用户选中的商品 取id
        let commodityGreyList: any = []
        pageData.spRowList.forEach(function (o: any) {
          commodityGreyList.push(o['id'])
        })
        //原料列表、
        let yarnStructure = ylTableList.value
        let greyInformations = dataForm
        ckpzobj.id = undefined
        // greyInformations['machineUnit'] = machineUnit.value
        greyInformations['theoryPrice'] = theoryPrice.value
        if (arrangementTriangle['info'] != undefined && arrangementTriangle['info'] != null) {
          arrangementTriangle['info'].map((o: any) => {
            o.typeData.map((a: any) => {
              a.needleList.map((b: any) => {
                b.circulationNum = xuanhuancihu.value
                b.realOpenNum = shikaishu.value
              })
            })
          })
        }
      }

      //判断账号是本集团还是外加工，判断编号是否可以修改
      const shifouxiugaibianhao = ref(null)
      const xuanzepaisanjiaolist = ref([]) as any
      const paishabiaoji = ref(0)

      //获取纱支编号,布类编号，功能编号
      // gncode: dataForm.feature,
      //                      szcode: dataForm.yarnCountCategory,
      //                      blcode: dataForm.mercery,
      const getsanbianhao = () => {
        post({
          url: 'product/mercery/getList',
          data: {
            merceryName: '',
            deleteState: '0',
          },
        }).then(({ data, code, message }: any) => {
          if (code === 200) {
            data.map((o: any) => {
              if (o.merceryName == dataForm.mercery) {
                buleibianhao.value = o.merceryCode
              }
            })
          } else {
            Message.error({
              content: message,
              duration: 5000,
            })
          }
        })
        post({
          url: '/product/Yarn/getYarnPara',
        }).then(({ data, code, message }: any) => {
          if (code === 200) {
            data.map((o: any) => {
              if (o.yarnName == dataForm.yarnCountCategory) {
                shazhibianhao.value = o.yarnCode
              }
            })
          } else {
            Message.error({
              content: message,
              duration: 5000,
            })
          }
        })
        post({
          url: 'product/greyInformationData/select',
          data: {
            greyInformationName: '',
            deleteState: '0',
          },
        }).then(({ data, code, message }: any) => {
          if (code === 200) {
            data.map((o: any) => {
              if (o.greyInformationName == dataForm.feature) {
                gongnengbianhao.value = o.greyInformation
              }
            })
          } else {
            Message.error({
              content: message,
              duration: 5000,
            })
          }
        })
      }
      const buleibianhao = ref('')
      const gongnengbianhao = ref('')
      const shazhibianhao = ref('')
      const handoff = (val: any) => {
        shenhebiaoji.value = val
        doRefresh()
      }
      const shenhe = (val: any) => {
        if (val == '待审核') {
          if (table1Ref.value.getSelectedRows().length === 0) {
            Message.error('请先勾选')
            return
          }
          var shenhelist = [] as any
          table1Ref.value.getSelectedRows().map((o: any) => {
            var obj = {
              id: o.id,
              auditState: 1,
            }
            shenhelist.push(obj)
          })
          post({
            url: '/product/pdGreyInformation/audit',
            data: shenhelist,
          }).then(({ data, code, message }: any) => {
            if (code === 200) {
              Message.success({
                content: simplifyMessages(message),
                duration: 500,
              })
              doRefresh()
            } else {
              Message.error({
                content: simplifyMessages(message),
                duration: 5000,
              })
            }
          })
        } else {
          if (table2Ref.value.getSelectedRows().length === 0) {
            Message.error('请先勾选')
            return
          }
          var shenhelist = [] as any
          table2Ref.value.getSelectedRows().map((o: any) => {
            var obj = {
              id: o.id,
              auditState: 0,
            }
            shenhelist.push(obj)
          })
          post({
            url: '/product/pdGreyInformation/audit',
            data: shenhelist,
          }).then(({ data, code, message }: any) => {
            if (code === 200) {
              Message.success({
                content: simplifyMessages(message),
                duration: 500,
              })
              doRefresh()
            } else {
              Message.error({
                content: simplifyMessages(message),
                duration: 5000,
              })
            }
          })
        }
      }
      const jitaileixing = () => {
        post({
          url: 'planSingle/machineType/getFieldValue',
          data: {
            typeName: '',
          },
        }).then((res: any) => {
          if (res.code == 200) {
            //pageData.machineTypeList = res.data
            pageData.machineTypeList = []
            res.data.map((o: any) => {
              pageData.machineTypeList.push({ typeName: o.typeName })
            })

            pageData.machineTypeList = Array.from(new Set(pageData.machineTypeList))
          }
        })
      }
      const crossMemo = ref('')
      const huancunpanduanziduan = ref('')
      const shezhishikailushu = () => {
        shikaishu.value = 12
      }
      const tongbupaisha = (record: any) => {
        ylTableList.value.map((o: any, index) => {
          psList.value.map((m: any, index2) => {
            if (index2 > 0) {
              if (index2 - 1 == index) {
                m.map((n: any, index3: any) => {
                  if (index3 == 1) {
                    n.val = o.yarnSource
                  }
                })
              }
            }
          })
        })
      }
      const caikoupaizhen = ref([]) as any

      //获取理论产量
      // let once=ref(true)
      function getTheoreticalYield(record: any) {
        if(record==''){
          return
        }
        console.log(record);
        
        //最开始的计算
        // if(!record.yarnCountProportion){
          jiShuanSha()
        post({
          url: 'product/pdGreyInformation/theoryYield',
          data: {
            sumNeedleCount: parseFloat(dataForm.sumNeedleCount),
            // "sumWay": dataForm.alwaysGoes,
            loomRevolution: dataForm.loomRevolution,
            rowInfo: ylTableList.value,
          },
        }).then(({ data, code, message }: any) => {
          if (code === 200) {
            dataForm.theoreticalYield = data
          } else {
            Message.error({
              content: message,
              duration: 5000,
            })
          }
        })
        // }

        
        //有值再弹窗提醒
        
        if(record.wayNum&&record.yarnLong&&record.yarnCountProportion&&ylTableList.value.length>0){
         
            Modal.confirm({
                title: '系统提示',
                content: '是否重新计算纱支比例?',
                onOk() {
                  jiShuanSha()
                  

        post({
          url: 'product/pdGreyInformation/theoryYield',
          data: {
            sumNeedleCount: parseFloat(dataForm.sumNeedleCount),
            // "sumWay": dataForm.alwaysGoes,
            loomRevolution: dataForm.loomRevolution,
            rowInfo: ylTableList.value,
          },
        }).then(({ data, code, message }: any) => {
          if (code === 200) {
           
            dataForm.theoreticalYield = data
          } else {
            Message.error({
              content: message,
              duration: 5000,
            })
          }
        })
                }
            })
          
         
     }
       

       
       
        // YarnLengthRule()
      }

      const getYarnUnitsList = () => {
        post({
          url: '/dict/dictTypeDetail/getListByCodeType?codeType=33',
          data: '',
        }).then(({ data, code }: any) => {
          if (code === 200) {
            pageData.yarnUnitsList = data
          } else {
            Message.error({
              content: '查询失败！',
              duration: 5000,
            })
          }
        })
      }

      function blurJx() {
        selectPsj(1)
        if (dataForm.machineType == '单面机') {
          pageData.tags = [
            { id: '1', val: '̶' },
            { id: '2', val: 'Ո' },
            { id: '4', val: 'Ʌ' },
          ]
          sjdata.sj = [
            {
              type: '下盘',
              typeData: [
                {
                  serialNumber: 1,
                  needleName: '',
                  needleList: [{ way: 1 }],
                },
                {
                  serialNumber: 2,
                  needleName: '',
                  needleList: [
                    {
                      needle: '',
                      way: 1,
                    },
                  ],
                },
                {
                  serialNumber: 3,
                  needleName: '',
                  needleList: [
                    {
                      needle: '',
                      way: 1,
                    },
                  ],
                },
                {
                  serialNumber: 4,
                  needleName: '',
                  needleList: [
                    {
                      needle: '',
                      way: 1,
                    },
                  ],
                },
              ],
            },
          ]
        } else {
          pageData.tags = [
            { id: '1', val: '̶' },
            { id: '2', val: 'Ո' },
            { id: '3', val: 'Ս' },
            {
              id: '4',
              val: 'Ʌ',
            },
            {
              id: '5',
              val: 'V',
            },
          ]
          sjdata.sj = [
            {
              type: '上盘',
              typeData: [
                {
                  serialNumber: 1,
                  needleName: '',
                  needleList: [
                    {
                      needle: '',
                      way: 1,
                    },
                  ],
                },
                {
                  serialNumber: 2,
                  needleName: '',
                  needleList: [
                    {
                      needle: '',
                      way: 1,
                    },
                  ],
                },
              ],
            },
            {
              type: '下盘',
              typeData: [
                {
                  serialNumber: 1,
                  needleName: '',
                  needleList: [{ way: 1 }],
                },
                {
                  serialNumber: 2,
                  needleName: '',
                  needleList: [
                    {
                      needle: '',
                      way: 1,
                    },
                  ],
                },
                {
                  serialNumber: 3,
                  needleName: '',
                  needleList: [
                    {
                      needle: '',
                      way: 1,
                    },
                  ],
                },
                {
                  serialNumber: 4,
                  needleName: '',
                  needleList: [
                    {
                      needle: '',
                      way: 1,
                    },
                  ],
                },
              ],
            },
          ]
        }
      }

      function selectPsj(num: any) {
        if (num == 2) {
          if (sjid.value == '' || sjid.value == undefined || sjid.value == null) {
            xuanzepaisanjiaolist.value = []
          }
        } else {
          xuanzepaisanjiaolist.value = []
          sjid.value = ''
        }
      }

      const jiShuanSha = () => {
        if (ylTableList.value.length == 0) {
          Message.error('请选择原料')
          return
        }
        if (ylTableList.value.length == 1) {
          nextTick(() => {
            ylTableList.value[0].yarnCountProportion = 100
          })
          return
        }
        let zhongHe = 0
        for (let i = 0; i < ylTableList.value.length; i++) {
          let dataObjs = ylTableList.value[i]
          if (!dataObjs.danielCoefficient || !dataObjs.yarnLong || !dataObjs.wayNum) {
            Message.error('丹尼尔系数,纱长,上纱路数 不可为空')
            return
          } else {
            zhongHe +=
              Number(dataObjs.danielCoefficient) *
              Number(dataObjs.yarnLong) *
              Number(dataObjs.wayNum)
            for (let i = 0; i < ylTableList.value.length; i++) {
              nextTick(() => {
                ylTableList.value[i].yarnCountProportion =
                  Number((((Number(ylTableList.value[i].danielCoefficient) *
                    Number(ylTableList.value[i].yarnLong) *
                    Number(ylTableList.value[i].wayNum)) /
                    zhongHe) *
                  100).toFixed(2))
              })
            }
          }
        }
      }
      const fySelet4: any = reactive({
        total: 10,
        size: 10,
        page: 1,
      })
      const PageSize4 = (val: any) => {
        fySelet4.page = val
        cxYlList()
      }

      const change4 = (val: any) => {
        fySelet4.size = val
        cxYlList()
      }

      const zlsList = ref()

      const zlsClick = () => {
        post({
          url: 'product/GreyWay/getList',
          data: { machineType: dataForm.orderMachineType, cunCount: dataForm.dimensionFigure },
        }).then(({ data }) => {
          zlsList.value = data
        })
      }

      /**
       * 订单机型选择数组
       */
      const ddjxList: any = ref()

      /**
       * 订单机型查询接口
       */
      const ddjxClick = () => {
        post({
          url: 'dict/dictTypeDetail/getListByCodeType?codeType=' + 46,
          // data: { codeType: 46 },
        }).then(({ data }) => {
          ddjxList.value = data
        })
      }
      const queryColorNumber = ref('')
      const queryNN = ref('')
      const colourNumberVisible = ref(false)
      const colourNumberLoading = ref(false)
      const colorNumberdata = ref([])
      const cNpagination = ref({
        page: 1,
        size: 10,
        total: 0,
      })

      const CNgridOption = ref(null)
      const colorNumberColumns = [
        {
          headerCheckboxSelection: false,
          checkboxSelection: true,
          width: 60,
          filter: false,
          sortable: false,
          resizable: false,
          showDisabledCheckboxes: false,
          pinned: 'left',
        },
        {
          headerName: '序号',
          field: 'colorCode',
          width: 150,
        },
        {
          headerName: '色称',
          field: 'colorName',
          width: 150,
        },
        {
          headerName: '色号',
          field: 'colorNumber',
          width: 150,
        },
        {
          headerName: '备注',
          field: 'remark',
          width: 150,
        },
      ]
      let tempRow
      const CNgridReady = (params: any) => {
        CNgridOption.value = params.api
      }
      const colourNumberClick = (row) => {
        if (pageData.isDetails) return
        colourNumberVisible.value = true
        tempRow = row
        colorNumberSearch()
      }
      const colourNumberOk = () => {
        if (CNgridOption.value.getSelectedRows().length === 0) {
          ElMessage.warning('请勾选您要填入的色号色称！')
          return false
        } else {
          const row = CNgridOption.value.getSelectedRows()[0]
          // const newData =[]
          // CNgridOption.value.forEachNode((node: any) => {
          //   if (node.data.id===row.id) {
          //     newData.push(row)
          //   }else{
          //     newData.push(node.data)
          //   }
          // })
          // ylTableList.value = newData
          nextTick(() => {
            tempRow.colourNumber = row.colorNumber
            tempRow.colorAccording = row.colorName
          })
          return true
        }
        // return true
      }
      const colourNumberClear = (row) => {
        row.colorAccording = ''
      }
      const colourNumberCancel = () => {
        colourNumberVisible.value = false
      }
      const colorNumberSearch = () => {
        colourNumberLoading.value = true
        post({
          url: 'product/color/getColorPage',
          data: {
            colorNumber: queryColorNumber.value,
            colorName: queryNN.value,
            deleteState: 0,
            obsoleteState: 0,
            page: cNpagination.value.page,
            size: cNpagination.value.size,
          },
        }).then(({ data, code }: any) => {
          if (code === 200) {
            colorNumberdata.value = data.list
            CNgridOption.value.setRowData(colorNumberdata.value)
            cNpagination.value.total = data.total
          } else {
            CNgridOption.value.setRowData([])
            cNpagination.value.total = 0
          }
          colourNumberLoading.value = false
        })
      }
      const handleDrawerCancel = () => {
        pageData.showAdd2 = false
        alignState.value = ['0']
        alignType.value = '0'
      }
      const isChecked = computed({
        get: () => dataForm.differentiateState == 2,
        set: (value) => {
          dataForm.differentiateState = value ? 2 : 4
        },
      })
      return {
        isChecked,
        ddjxClick,
        ddjxList,
        zlsClick,
        zlsList,
        fySelet4,
        PageSize4,
        change4,
        colState,
        colState2,
        jiShuanSha,
        zzpzSelectType,
        focusJgCx,
        selectPsj,
        getWayNum,
        blurJx,
        getYarnUnitsList,
        getTheoreticalYield,
        getwuliao,
        caikoupaizhen,
        tongbupaisha,
        huancunpanduanziduan,
        crossMemo,
        shenhe,
        shenhebiaoji,
        handoff,
        gridReady2,
        gridOption2,
        buleibianhao,
        gongnengbianhao,
        shazhibianhao,
        paishabiaoji,
        xuanzepaisanjiaolist,
        shifouxiugaibianhao,
        fuzhixinzengindex,
        fuzhixinzeng,
        yichu,
        xuanranpaisha,
        wdbiaoji,
        wdfz,
        theoryPrice,
        isshow,
        id,
        shabilist,
        shabili,
        wuliaoname,
        pdbiaoji,
        jinxingfuzhi,
        // iscopy,
        fuzhixiala,
        isBan,
        getcolornumber,
        colornamelist,
        colorname,
        dengjilist,
        dengji,
        colornumberlist,
        colornumber,
        machineUnit,
        gaibian,
        pagingList1,
        // getwuliao,
        xunhuan,
        xuanhuancihu,
        shikaishu,
        duiqiheight,
        jixing,
        YarnLengthRule,
        formRef1,
        huiche,
        focusPs,
        localeText1,
        jgCxArray,
        jgCx,
        isEng,
        totalOnehundred,
        zhongAndYin,
        fabricTypeList,
        fabricTypeSelect,
        fabricTypeFocus,
        putOnRecordsCodeRules,
        ExploitCodeRules,
        cxYlList,
        ylData,
        focusSelYl,
        optionsYl,
        handleSearchYl,
        ylColumns,
        selectedRowKeysAddYl,
        handleClick1,
        handleCancel1,
        visible1,
        defaultColDef,
        shuaxinpaisha,
        cancelPop,
        handleChange,
        psEditList,
        moreEdit,
        handleClick,
        handleBeforeOk,
        handleCancel,
        visible,
        total,
        PageSize,
        change1,
        page,
        size,
        sptablecol,
        spSelectList,
        sp,
        spSelect,
        ewsj,
        psjpbOk,
        psjpblist,
        psjpb,
        psjpblistSelect,
        colNumber,
        codeGen,
        codeGens,
        szSelect,
        gnSelect,
        blList,
        blSelect,
        gnList,
        szList,
        numb,
        tagValue,
        sm,
        setSJValue,
        sjhasnull,
        tags,
        setNum,
        setNum1,
        subRow,
        addRow,
        subCol,
        addCol,
        sjid,
        sjdata,
        sjSelect,
        sjSelectList,
        sjOk,
        copyckpz,
        ckpzobj,
        ckpzSelectList,
        ckpzadd,
        ckpzid,
        ckpzSelect,
        zzpzok,
        zzpzdata,
        zzpzListSelect,
        zzpzid,
        zzpzSelect,
        ckpzfocus,
        zzpzfocus,
        addYl,
        ylTableList,
        ylSelect,
        ylList,
        deleteHandler,
        sideOk,
        formRef,
        dataForm,
        addHandler,
        selectedRowKeys,
        pagination,
        tableColumns,
        table,
        rowKey,
        pageData,
        queryData,
        changeFirm,
        editHandler,
        tableColumns1,
        selectHandler,
        focusSel,
        focusSel1,
        focusSel2,
        focusSel3,
        focusSel4,
        focusSel9,
        focusNeedleCountList,
        searchNeedleCountList,
        searchMachineTypeList,
        focusMachineTypeList,
        searchColorAttribute,
        focusColorAttribute,
        searchUnit,
        focusunit,
        focusYl,
        changeNeedleCount,
        options,
        loading,
        handleSearch,
        options1,
        loading1,
        handleSearch1,
        options2,
        loading2,
        handleSearch2,
        options3,
        loading3,
        handleSearch3,
        options4,
        loading4,
        handleSearch4,
        ylId,
        minsZhen,
        addZhen,
        headerShow,
        focusSp,
        handleSearch5,
        options5,
        loading5,
        options6,
        loading6,
        addSpRow,
        delSpRow,
        selectedRowKeysSp,
        focusSel6,
        handleSearch6,
        changeYarnSource,
        delYl,
        focusGn,
        focusBl,
        focusSj,
        psList,
        changeXh,
        xhCol,
        gridReady,
        permissionStore,
        table1Ref,
        configTable1,
        getTable1Data,
        table2Ref,
        configTable2,
        getTable2Data,
        settingLoopVisible,
        setLoop,
        settingLoopOK,
        settingLoopColumns,
        settingLoopData,
        settingLoopKeys,
        settingLoopCheckBox,
        wayEndChange,
        loopCountChange,
        loopAdd,
        loopDel,
        countLoopBetween,
        addFlag,
        TempSettingLoopData,
        setSPData,
        getLoopWayNum,
        clearPSJTempData,
        showwarning,
        colourNumberClick,
        queryNN,
        queryColorNumber,
        colourNumberVisible,
        colourNumberOk,
        colourNumberCancel,
        colourNumberLoading,
        colorNumberSearch,
        colorNumberColumns,
        colorNumberdata,
        CNgridReady,
        CNgridOption,
        colourNumberClear,
        cNpagination,
        alignState,
        alignStateOptions,
        alignStateChange,
        alignType,
        handleDrawerCancel,
      }
    },
    components: { Toolbar,  },
  }
</script>
<style scoped lang="less">
  .thead {
    white-space: nowrap;
    justify-content: center;

    .th {
      padding: 5px;
      box-sizing: border-box;
      text-align: center;
      display: inline-block;
    }

    width: 100%;
    text-align: left;
  }

  .tbody {
    white-space: nowrap;
    justify-content: center;

    .td {
      text-align: center;
      padding: 5px;
      box-sizing: border-box;
      display: inline-block;
    }

    text-align: left;
  }

  .trow > div {
    display: inline-block;
    text-align: center;
  }

  .active {
    width: 80px !important;
  }

  .arco-input-wrapper {
    padding-left: 5px !important;
    padding-right: 5px !important;
  }

  .arco-select-view-single {
    padding-left: 5px !important;
    padding-right: 5px !important;
  }

  .arco-collapse-item-content {
    padding-left: 0px !important;
    padding-right: 0px !important;
  }

  .demo-basic {
    padding: 10px;
    width: 200px;
    background-color: var(--color-bg-popup);
    border-radius: 4px;
    box-shadow: 0 2px 8px 0 rgba(0, 0, 0, 0.15);
  }

  :deep(.arco-collapse-item-active > .arco-collapse-item-header) {
    background: #00a8ea !important;
  }
  .opcity-ipt {
    opacity: 0.5;
  }
</style>
